aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authoronefang2020-05-16 15:21:20 +1000
committeronefang2020-05-16 15:21:20 +1000
commit641643a8970993204252074c597b2ebc631c7d71 (patch)
treef4e446defd73988c7f79718d993850269cc9563c /src
parentNo more database leaks. (diff)
downloadopensim-SC-641643a8970993204252074c597b2ebc631c7d71.zip
opensim-SC-641643a8970993204252074c597b2ebc631c7d71.tar.gz
opensim-SC-641643a8970993204252074c597b2ebc631c7d71.tar.bz2
opensim-SC-641643a8970993204252074c597b2ebc631c7d71.tar.xz
Fix the last of the known leaks.
Diffstat (limited to 'src')
-rw-r--r--src/sledjchisl/sledjchisl.c115
1 files changed, 78 insertions, 37 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c
index ddb041d..02bebe6 100644
--- a/src/sledjchisl/sledjchisl.c
+++ b/src/sledjchisl/sledjchisl.c
@@ -845,6 +845,7 @@ int checkSimIsRunning(char *sim)
845 } 845 }
846 } 846 }
847 } 847 }
848 free(pid);
848 } 849 }
849 850
850 // Now check if it's really really running. lol 851 // Now check if it's really really running. lol
@@ -1845,18 +1846,20 @@ void dbPull(reqData *Rd, char *table, rowData *rows)
1845 qhashtbl_t *me = rows->rows->popfirst(rows->rows, NULL); 1846 qhashtbl_t *me = rows->rows->popfirst(rows->rows, NULL);
1846 qhashtbl_obj_t obj; 1847 qhashtbl_obj_t obj;
1847 1848
1848 memset((void*)&obj, 0, sizeof(obj)); 1849 if (NULL != me)
1849 me->lock(me);
1850 while(me->getnext(me, &obj, false) == true)
1851 { 1850 {
1852 where = xmprintf("%s.%s", table, obj.name); 1851 memset((void*)&obj, 0, sizeof(obj));
1852 me->lock(me);
1853 while(me->getnext(me, &obj, false) == true)
1854 {
1855 where = xmprintf("%s.%s", table, obj.name);
1853d("dbPull(Rd->database) %s = %s", where, (char *) obj.data); 1856d("dbPull(Rd->database) %s = %s", where, (char *) obj.data);
1854 Rd->database->putstr(Rd->database, where, (char *) obj.data); 1857 Rd->database->putstr(Rd->database, where, (char *) obj.data);
1855// me->remove(me, obj.name); 1858 free(where);
1856 free(where); 1859 }
1860 me->unlock(me);
1861 me->free(me);
1857 } 1862 }
1858 me->unlock(me);
1859 me->free(me);
1860 free(rows->fieldNames); 1863 free(rows->fieldNames);
1861 rows->rows->free(rows->rows); 1864 rows->rows->free(rows->rows);
1862 free(rows); 1865 free(rows);
@@ -2202,8 +2205,6 @@ gridStats *getStats(MYSQL *db, gridStats *stats)
2202 else 2205 else
2203 y = atoll(tmp); 2206 y = atoll(tmp);
2204 simSize += x * y; 2207 simSize += x * y;
2205// TODO - I can't win. valgrind complains that either something is being freed twice, or not freed at all, no matter what I do.
2206// This seems to keep the memory loss down to a minimum.
2207 row->free(row); 2208 row->free(row);
2208 rows->rows->removefirst(rows->rows); 2209 rows->rows->removefirst(rows->rows);
2209 } 2210 }
@@ -2300,6 +2301,18 @@ struct _cookie
2300 enum cookieSame site; 2301 enum cookieSame site;
2301}; 2302};
2302 2303
2304void freeCookie(reqData *Rd, char *cki)
2305{
2306 cookie *ck0 = Rd->Rcookies->get(Rd->Rcookies, cki, NULL, false);
2307
2308 if (NULL != ck0)
2309 {
2310 if (NULL != ck0->value)
2311 free(ck0->value);
2312 Rd->Rcookies->remove(Rd->Rcookies, cki);
2313 }
2314}
2315
2303cookie *setCookie(reqData *Rd, char *cki, char *value) 2316cookie *setCookie(reqData *Rd, char *cki, char *value)
2304{ 2317{
2305 cookie *ret = xzalloc(sizeof(cookie)); 2318 cookie *ret = xzalloc(sizeof(cookie));
@@ -2308,6 +2321,7 @@ cookie *setCookie(reqData *Rd, char *cki, char *value)
2308 2321
2309 // Validate this, as there is a limited set of characters allowed. 2322 // Validate this, as there is a limited set of characters allowed.
2310 qstrreplace("tr", cook, "()<>@,;:\\\"/[]?={} \t", "_"); 2323 qstrreplace("tr", cook, "()<>@,;:\\\"/[]?={} \t", "_");
2324 freeCookie(Rd, cook);
2311 l = strlen(cook); 2325 l = strlen(cook);
2312 for (i = 0; i < l; i++) 2326 for (i = 0; i < l; i++)
2313 { 2327 {
@@ -2316,9 +2330,9 @@ cookie *setCookie(reqData *Rd, char *cki, char *value)
2316 } 2330 }
2317 l = strlen(value); 2331 l = strlen(value);
2318 if (0 != l) 2332 if (0 != l)
2319 ret->value = qurl_encode(value, l); // LEAKY 2333 ret->value = qurl_encode(value, l);
2320 else 2334 else
2321 ret->value = xstrdup(""); // LEAKY 2335 ret->value = xstrdup("");
2322 ret->httpOnly = TRUE; 2336 ret->httpOnly = TRUE;
2323 ret->site = CS_STRICT; 2337 ret->site = CS_STRICT;
2324 ret->secure = TRUE; 2338 ret->secure = TRUE;
@@ -2331,16 +2345,6 @@ cookie *setCookie(reqData *Rd, char *cki, char *value)
2331 return ret; 2345 return ret;
2332} 2346}
2333 2347
2334void freeCookie(reqData *Rd, char *cki)
2335{
2336 cookie *ck0 = Rd->cookies->get(Rd->cookies, cki, NULL, false);
2337
2338// TODO - Crash or leak, there is no free.
2339// if ((NULL != ck0) && (NULL != ck0->value))
2340// free(ck0->value);
2341 Rd->cookies->remove(Rd->cookies, cki);
2342}
2343
2344char *getCookie(qhashtbl_t *cookies, char *cki) 2348char *getCookie(qhashtbl_t *cookies, char *cki)
2345{ 2349{
2346 char *ret = NULL; 2350 char *ret = NULL;
@@ -3533,7 +3537,7 @@ t("Write shs %s", tnm4);
3533 { 3537 {
3534// TODO - Later use libcurl. 3538// TODO - Later use libcurl.
3535 3539
3536 char *uuid = Rd->shs.UUID, *first = getStrH(Rd->stuff, "firstName"), *last = getStrH(Rd->stuff, "lastName"); 3540 char *first = getStrH(Rd->stuff, "firstName"), *last = getStrH(Rd->stuff, "lastName");
3537// TODO - should be from Rd.shs->linky-hashish 3541// TODO - should be from Rd.shs->linky-hashish
3538 char *t0 = xstrdup(Rd->lnk->hashish), *content, *command; 3542 char *t0 = xstrdup(Rd->lnk->hashish), *content, *command;
3539 3543
@@ -3620,6 +3624,7 @@ static void generateAccountUUID(reqData *Rd)
3620 users = dbCount(Rd->db, "UserAccounts", where); 3624 users = dbCount(Rd->db, "UserAccounts", where);
3621 free(where); 3625 free(where);
3622 } while (users != 0); 3626 } while (users != 0);
3627 if (NULL != Rd->shs.UUID) free(Rd->shs.UUID);
3623 Rd->shs.UUID = xstrdup(uuid); 3628 Rd->shs.UUID = xstrdup(uuid);
3624 Rd->shs.level = -200; 3629 Rd->shs.level = -200;
3625 Rd->database->putstr(Rd->database, "UserAccounts.PrincipalID", uuid); 3630 Rd->database->putstr(Rd->database, "UserAccounts.PrincipalID", uuid);
@@ -4113,7 +4118,7 @@ T("new sesh %s %s %s", linky ? "linky" : "session", ret->UUID, ret->name);
4113 { 4118 {
4114 uuid_clear(binuuid); 4119 uuid_clear(binuuid);
4115 uuid_unparse_lower(binuuid, uuid); 4120 uuid_unparse_lower(binuuid, uuid);
4116 ret->UUID = uuid; 4121 ret->UUID = xstrdup(uuid);
4117 } 4122 }
4118 t0 = xmprintf("%s%s", ret->UUID, munchie); 4123 t0 = xmprintf("%s%s", ret->UUID, munchie);
4119 free(munchie); 4124 free(munchie);
@@ -4354,8 +4359,10 @@ W("Validated session.");
4354 sesh *shs = &Rd->shs; 4359 sesh *shs = &Rd->shs;
4355 4360
4356 qstrcpy(shs->leaf, sizeof(shs->leaf), leaf); 4361 qstrcpy(shs->leaf, sizeof(shs->leaf), leaf);
4357 shs->name = tnm->getstr(tnm, "name", true); // LEAKY! 4362 if (NULL != shs->name) free(shs->name);
4358 shs->UUID = tnm->getstr(tnm, "UUID", true); // LEAKY! 4363 shs->name = tnm->getstr(tnm, "name", true);
4364 if (NULL != shs->UUID) free(shs->UUID);
4365 shs->UUID = tnm->getstr(tnm, "UUID", true);
4359 if (linky) 4366 if (linky)
4360 { 4367 {
4361W("Validated session linky."); 4368W("Validated session linky.");
@@ -4562,7 +4569,8 @@ static int nameValidate(reqData *Rd, inputForm *iF, inputValue *iV)
4562 Rd->stuff->putstrf(Rd->stuff, "name", "%s %s", name, s); 4569 Rd->stuff->putstrf(Rd->stuff, "name", "%s %s", name, s);
4563// TODO - fix this, so we don't show "You are user" when we are not, but everything else still works. 4570// TODO - fix this, so we don't show "You are user" when we are not, but everything else still works.
4564// if ('\0' != getStrH(Rd->queries, "user")[0]) 4571// if ('\0' != getStrH(Rd->queries, "user")[0])
4565 Rd->shs.name = Rd->stuff->getstr(Rd->stuff, "name", true); // LEAKY 4572 if (NULL != Rd->shs.name) free(Rd->shs.name);
4573 Rd->shs.name = Rd->stuff->getstr(Rd->stuff, "name", true);
4566 } 4574 }
4567 } 4575 }
4568 } 4576 }
@@ -4988,7 +4996,7 @@ static void accountLoginWeb(reqData *Rd, inputForm *oF, inputValue *oV)
4988{ 4996{
4989 if (NULL != Rd->shs.name) free(Rd->shs.name); 4997 if (NULL != Rd->shs.name) free(Rd->shs.name);
4990 Rd->shs.name = NULL; 4998 Rd->shs.name = NULL;
4991// if (NULL != Rd->shs.UUID) free(Rd->shs.UUID); // LEAKY! And crashy! 4999 if (NULL != Rd->shs.UUID) free(Rd->shs.UUID);
4992 Rd->shs.UUID = NULL; 5000 Rd->shs.UUID = NULL;
4993 accountWebHeaders(Rd, oF); 5001 accountWebHeaders(Rd, oF);
4994 accountWebFields(Rd, oF, oV); 5002 accountWebFields(Rd, oF, oV);
@@ -5221,7 +5229,8 @@ d("accountRead() UUID %s, name %s %s", uuid, first, last);
5221 Rd->database->putstr(Rd->database, "Lua.vouched", getStrH(tnm, "vouched")); 5229 Rd->database->putstr(Rd->database, "Lua.vouched", getStrH(tnm, "vouched"));
5222 Rd->database->putstr(Rd->database, "Lua.voucher", getStrH(tnm, "voucher")); 5230 Rd->database->putstr(Rd->database, "Lua.voucher", getStrH(tnm, "voucher"));
5223 } 5231 }
5224 else if (rows) 5232// else if (rows)
5233 if (rows)
5225 { 5234 {
5226 ret += rows->rows->size(rows->rows); 5235 ret += rows->rows->size(rows->rows);
5227 if (1 == ret) 5236 if (1 == ret)
@@ -5239,8 +5248,26 @@ d("accountRead() UUID %s, name %s %s", uuid, first, last);
5239 { 5248 {
5240 if (1 == rows->rows->size(rows->rows)) 5249 if (1 == rows->rows->size(rows->rows))
5241 dbPull(Rd, "auth", rows); 5250 dbPull(Rd, "auth", rows);
5251 else
5252 {
5253 free(rows->fieldNames);
5254 rows->rows->free(rows->rows);
5255 free(rows);
5256 }
5257 }
5258 else
5259 {
5260 free(rows->fieldNames);
5261 rows->rows->free(rows->rows);
5262 free(rows);
5242 } 5263 }
5243 } 5264 }
5265 else
5266 {
5267 free(rows->fieldNames);
5268 rows->rows->free(rows->rows);
5269 free(rows);
5270 }
5244 } 5271 }
5245 else 5272 else
5246 { 5273 {
@@ -5483,8 +5510,10 @@ d("Sub accountViewSub() %s %s %s", uuid, first, last);
5483 else 5510 else
5484 { 5511 {
5485 Rd->shs.level = atoi(getStrH(Rd->database, "UserAccounts.UserLevel")); 5512 Rd->shs.level = atoi(getStrH(Rd->database, "UserAccounts.UserLevel"));
5486 Rd->shs.name = Rd->database->getstr(Rd->database, "Lua.name", true); // LEAKY 5513 if (NULL != Rd->shs.name) free(Rd->shs.name);
5487 Rd->shs.UUID = Rd->database->getstr(Rd->database, "UserAccounts.PrincipalID", true); // LEAKY 5514 Rd->shs.name = Rd->database->getstr(Rd->database, "Lua.name", true);
5515 if (NULL != Rd->shs.UUID) free(Rd->shs.UUID);
5516 Rd->shs.UUID = Rd->database->getstr(Rd->database, "UserAccounts.PrincipalID", true);
5488 free(h); 5517 free(h);
5489 I("Logged on %s %s Level %d %s", Rd->shs.UUID, Rd->shs.name, Rd->shs.level, getLevel(Rd->shs.level)); 5518 I("Logged on %s %s Level %d %s", Rd->shs.UUID, Rd->shs.name, Rd->shs.level, getLevel(Rd->shs.level));
5490 Rd->shs.status = SHS_LOGIN; 5519 Rd->shs.status = SHS_LOGIN;
@@ -5677,7 +5706,7 @@ void inputFieldExtra(inputField *ret, signed char flags, short viewLength, short
5677 5706
5678void addSession(inputForm *iF) 5707void addSession(inputForm *iF)
5679{ 5708{
5680 inputField *fld, **flds = xzalloc(3 * sizeof(*flds)); // LEAKY! 5709 inputField *fld, **flds = xzalloc(3 * sizeof(*flds));
5681 5710
5682//d("addSession(%s)", iF->name); 5711//d("addSession(%s)", iF->name);
5683 flds[0] = addInputField(iF, LUA_TSTRING, "hashish", "hashish", "", sessionValidate, sessionWeb); 5712 flds[0] = addInputField(iF, LUA_TSTRING, "hashish", "hashish", "", sessionValidate, sessionWeb);
@@ -5693,7 +5722,7 @@ void addSession(inputForm *iF)
5693 5722
5694void addEmailFields(inputForm *iF) 5723void addEmailFields(inputForm *iF)
5695{ 5724{
5696 inputField *fld, **flds = xzalloc(3 * sizeof(*flds)); // LEAKY! 5725 inputField *fld, **flds = xzalloc(3 * sizeof(*flds));
5697 5726
5698 flds[0] = addInputField(iF, LUA_TEMAIL, "email", "email", NULL, emailValidate, emailWeb); 5727 flds[0] = addInputField(iF, LUA_TEMAIL, "email", "email", NULL, emailValidate, emailWeb);
5699 inputFieldExtra(flds[0], FLD_EDITABLE, 42, 254); 5728 inputFieldExtra(flds[0], FLD_EDITABLE, 42, 254);
@@ -5709,7 +5738,7 @@ void addEmailFields(inputForm *iF)
5709 5738
5710void addDoBFields(inputForm *iF) 5739void addDoBFields(inputForm *iF)
5711{ 5740{
5712 inputField *fld, **flds = xzalloc(3 * sizeof(*flds)); // LEAKY! 5741 inputField *fld, **flds = xzalloc(3 * sizeof(*flds));
5713 5742
5714 flds[0] = addInputField(iF, LUA_TSTRING, "DoByear", "year", NULL, DoBValidate, DoByWeb); 5743 flds[0] = addInputField(iF, LUA_TSTRING, "DoByear", "year", NULL, DoBValidate, DoByWeb);
5715 flds[1] = addInputField(iF, LUA_TSTRING, "DoBmonth", "month", NULL, DoBValidate, DoBmWeb); 5744 flds[1] = addInputField(iF, LUA_TSTRING, "DoBmonth", "month", NULL, DoBValidate, DoBmWeb);
@@ -5722,7 +5751,7 @@ void addDoBFields(inputForm *iF)
5722 5751
5723void addLegalFields(inputForm *iF) 5752void addLegalFields(inputForm *iF)
5724{ 5753{
5725 inputField *fld, **flds = xzalloc(3 * sizeof(*flds)); // LEAKY! 5754 inputField *fld, **flds = xzalloc(3 * sizeof(*flds));
5726 5755
5727 flds[0] = addInputField(iF, LUA_TBOOLEAN, "adult", "I'm allegedly an adult in my country.", NULL, legalValidate, adultWeb); 5756 flds[0] = addInputField(iF, LUA_TBOOLEAN, "adult", "I'm allegedly an adult in my country.", NULL, legalValidate, adultWeb);
5728 flds[1] = addInputField(iF, LUA_TBOOLEAN, "agree", "I accept the Terms of Service.", NULL, legalValidate, agreeWeb); 5757 flds[1] = addInputField(iF, LUA_TBOOLEAN, "agree", "I accept the Terms of Service.", NULL, legalValidate, agreeWeb);
@@ -6337,6 +6366,18 @@ static void cleanup(void)
6337 6366
6338//d("%s = %s", obj.name, (char *) obj.data); 6367//d("%s = %s", obj.name, (char *) obj.data);
6339 f->subs->free(f->subs); 6368 f->subs->free(f->subs);
6369 qlisttbl_obj_t fobj;
6370
6371 memset((void *) &fobj, 0, sizeof(fobj));
6372 f->fields->lock(f->fields);
6373 while(f->fields->getnext(f->fields, &fobj, NULL, false) == true)
6374 {
6375 inputField *fld = (inputField *) fobj.data;
6376
6377 if (LUA_TGROUP == fld->type)
6378 free(fld->group);
6379 }
6380 f->fields->unlock(f->fields);
6340 f->fields->free(f->fields); 6381 f->fields->free(f->fields);
6341 } 6382 }
6342 accountPages->unlock(accountPages); 6383 accountPages->unlock(accountPages);
@@ -7081,7 +7122,7 @@ fcgiDone:
7081 if (NULL != Rd->outQuery) free(Rd->outQuery); 7122 if (NULL != Rd->outQuery) free(Rd->outQuery);
7082 if (NULL != Rd->shs.name) free(Rd->shs.name); 7123 if (NULL != Rd->shs.name) free(Rd->shs.name);
7083 Rd->shs.name = NULL; 7124 Rd->shs.name = NULL;
7084// if (NULL != Rd->shs.UUID) free(Rd->shs.UUID); // LEAKY! But crashy! 7125 if (NULL != Rd->shs.UUID) free(Rd->shs.UUID);
7085 Rd->shs.UUID = NULL; 7126 Rd->shs.UUID = NULL;
7086 qgrow_free(Rd->reply); 7127 qgrow_free(Rd->reply);
7087 qlist_free(Rd->messages); 7128 qlist_free(Rd->messages);