From 228df6a08a83ac4cd7910670b367feaceb417be4 Mon Sep 17 00:00:00 2001 From: onefang Date: Thu, 14 May 2020 20:23:23 +1000 Subject: Leakies +/- --- src/sledjchisl/sledjchisl.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'src/sledjchisl') diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index f3411d8..5a06fa2 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -2329,10 +2329,9 @@ cookie *setCookie(reqData *Rd, char *cki, char *value) } l = strlen(value); if (0 != l) - ret->value = qurl_encode(value, l); + ret->value = qurl_encode(value, l); // LEAKY else -// TODO - I'm doing something crazy again, this isn't crashing when I try to free it. Sometimes. Heisenbug? - ret->value = ""; + ret->value = xstrdup(""); // LEAKY ret->httpOnly = TRUE; ret->site = CS_STRICT; ret->secure = TRUE; @@ -2345,6 +2344,16 @@ cookie *setCookie(reqData *Rd, char *cki, char *value) return ret; } +void freeCookie(reqData *Rd, char *cki) +{ + cookie *ck0 = Rd->cookies->get(Rd->cookies, cki, NULL, false); + +// TODO - Crash or leak, there is no free. +// if ((NULL != ck0) && (NULL != ck0->value)) +// free(ck0->value); + Rd->cookies->remove(Rd->cookies, cki); +} + char *getCookie(qhashtbl_t *cookies, char *cki) { char *ret = NULL; @@ -3374,9 +3383,8 @@ T("free sesh %s %s", linky ? "linky" : "session", wipe ? "wipe" : "delete"); Rd->body-> remove(Rd->body, "munchie"); - Rd->cookies->remove(Rd->cookies, "toke_n_munchie"); - Rd->cookies->remove(Rd->cookies, "hashish"); - + freeCookie(Rd, "toke_n_munchie"); + freeCookie(Rd, "hashish"); cookie *ck = setCookie(Rd, "toke_n_munchie", ""); cookie *ckh = setCookie(Rd, "hashish", ""); ck->maxAge = -1; // Should expire immediately. @@ -4567,7 +4575,7 @@ static int nameValidate(reqData *Rd, inputForm *iF, inputValue *iV) Rd->stuff->putstrf(Rd->stuff, "name", "%s %s", name, s); // TODO - fix this, so we don't show "You are user" when we are not, but everything else still works. // if ('\0' != getStrH(Rd->queries, "user")[0]) - Rd->shs.name = Rd->stuff->getstr(Rd->stuff, "name", true); + Rd->shs.name = Rd->stuff->getstr(Rd->stuff, "name", true); // LEAKY } } } @@ -5024,8 +5032,6 @@ static void accountViewWeb(reqData *Rd, inputForm *oF, inputValue *oV) HTMLtextArea(Rd->reply, "aboutMe", "About", 7, 50, 4, 16384, "", "off", "true", "soft", about, FALSE, TRUE); accountWebSubs(Rd, oF); accountWebFooter(Rd, oF); - free(about); free(voucher); free(email); - } static void accountEditWeb(reqData *Rd, inputForm *oF, inputValue *oV) @@ -5490,8 +5496,8 @@ d("Sub accountViewSub() %s %s %s", uuid, first, last); else { Rd->shs.level = atoi(getStrH(Rd->database, "UserAccounts.UserLevel")); - Rd->shs.name = Rd->database->getstr(Rd->database, "Lua.name", true); - Rd->shs.UUID = Rd->database->getstr(Rd->database, "UserAccounts.PrincipalID", true); + Rd->shs.name = Rd->database->getstr(Rd->database, "Lua.name", true); // LEAKY + Rd->shs.UUID = Rd->database->getstr(Rd->database, "UserAccounts.PrincipalID", true); // LEAKY free(h); I("Logged on %s %s Level %d %s", Rd->shs.UUID, Rd->shs.name, Rd->shs.level, getLevel(Rd->shs.level)); Rd->shs.status = SHS_LOGIN; @@ -5570,14 +5576,14 @@ static int accountFilterValidated(struct dirtree *node) struct stat st; struct timespec now; RdAndListTbl *rdl = (RdAndListTbl *) node->parent->extra; - qhashtbl_t *tnm = qhashtbl(0, 0); // LEAKY! + qhashtbl_t *tnm = qhashtbl(0, 0); char *name = node->name; char *where = xmprintf("%s/users/%s", scData, node->name); int rt = LuaToHash(rdl->Rd, where, "user", tnm, 0, &st, &now, "user"); t("accountFilterValidatedVoucher %s (%s) -> %s -> %s", name, getStrH(tnm, "level"), getStrH(tnm, "name"), getStrH(tnm, "voucher")); if ((0 == rt) && (strcmp("-100", getStrH(tnm, "level")) == 0)) - rdl->list->put(rdl->list, getStrH(tnm, "name"), tnm, sizeof(*tnm)); + rdl->list->put(rdl->list, getStrH(tnm, "name"), &tnm, sizeof(qhashtbl_t *)); else tnm->free(tnm); free(where); @@ -5601,7 +5607,6 @@ qlisttbl_t *getAccounts(reqData *Rd) static void accountExploreValidatedVouchersWeb(reqData *Rd, inputForm *oF, inputValue *oV) { qlisttbl_t *list =getAccounts(Rd); -// char *name = getStrH(Rd->stuff, "name"); if (NULL != Rd->shs.name) free(Rd->shs.name); Rd->shs.name = NULL; @@ -5625,16 +5630,15 @@ static void accountExploreValidatedVouchersWeb(reqData *Rd, inputForm *oF, input list->lock(list); while(list->getnext(list, &obj, NULL, false) == true) { - qhashtbl_t *tnm = (qhashtbl_t *) obj.data; + qhashtbl_t *tnm = *((qhashtbl_t **) obj.data); char *nm = qstrreplace("tr", xstrdup(obj.name), " ", "+"); Rd->reply->addstrf(Rd->reply, "%s", Rd->Host, Rd->RUri, nm, obj.name); Rd->reply->addstrf(Rd->reply, "%s%s%s", getStrH(tnm, "voucher"), getStrH(tnm, "level"), getStrH(tnm, "title")); free(nm); tnm->clear(tnm); -// TODO - crazy time again, either it frees twice, or not at all. -// list->removeobj(list, &obj); -// tnm->free(tnm); + list->removeobj(list, &obj); + tnm->free(tnm); } list->unlock(list); Rd->reply->addstr(Rd->reply, ""); @@ -6349,7 +6353,7 @@ static void cleanup(void) memset((void*)&obj, 0, sizeof(obj)); accountPages->lock(accountPages); - while(accountPages->getnext(accountPages, &obj, true) == true) + while(accountPages->getnext(accountPages, &obj, false) == true) { inputForm *f = (inputForm *) obj.data; @@ -6372,7 +6376,7 @@ static void cleanup(void) memset((void*)&obj, 0, sizeof(obj)); HTMLfileCache->lock(HTMLfileCache); - while(HTMLfileCache->getnext(HTMLfileCache, &obj, true) == true) + while(HTMLfileCache->getnext(HTMLfileCache, &obj, false) == true) { HTMLfile *f = (HTMLfile *) obj.data; @@ -7068,6 +7072,7 @@ sendReply: if (CS_NONE == ck->site) FCGI_printf("; SameSite=None"); FCGI_printf("\r\n"); free(ck->value); + ck->value = NULL; } FCGI_printf("\r\n"); Rd->cookies->unlock(Rd->cookies); -- cgit v1.1