From 354389d88678bf26ba30002d9184c0a1365556ec Mon Sep 17 00:00:00 2001 From: onefang Date: Wed, 20 May 2020 14:24:32 +1000 Subject: Leaks -= --- src/sledjchisl/sledjchisl.c | 47 ++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index bacab21..59e00ae 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -735,11 +735,21 @@ simList *getSims() struct dirtree *new = dirtree_add_node(0, path, 0); new->extra = (long) sims; dirtree_handle_callback(new, filterSims); + qsort(sims->sims, sims->num, sizeof(char *), qstrcmp); free(path); return sims; } +void freeSimList(simList *sims) +{ + int i; + + for (i = 0; i < sims->num; i++) + free(sims->sims[i]); + free(sims->sims); + free(sims); +} static int filterInis(struct dirtree *node) { @@ -747,7 +757,7 @@ static int filterInis(struct dirtree *node) int l = strlen(node->name); if (strncmp(&(node->name[l - 4]), ".ini", 4) == 0) { - strcpy((char *) node->parent->extra, xstrdup(node->name)); + strcpy((char *) node->parent->extra, node->name); return DIRTREE_ABORT; } return 0; @@ -773,12 +783,12 @@ char *getSimName(char *sim) temp = xmprintf("%s/config/%s/%s", scRoot, sim, c); fd = xopenro(temp); - free(temp); xregcomp(&pat, "RegionName = \"(.+)\"", REG_EXTENDED); do { // TODO - get_line() is slow, and wont help much with DOS and Mac line endings. // gio_gets() isn't any faster really, but deals with DOS line endings at least. + free(temp); temp = get_line(fd); if (temp) { @@ -788,6 +798,7 @@ char *getSimName(char *sim) if (pat.re_nsub > 0) { ret = xmprintf("%.*s", (int) (m[1].rm_eo - m[1].rm_so), temp + m[1].rm_so); + free(temp); break; } } @@ -2342,7 +2353,6 @@ cookie *setCookie(reqData *Rd, char *cki, char *value) free(ret); ret = Rd->Rcookies->get(Rd->Rcookies, cook, NULL, false); free(cook); - return ret; } @@ -2353,7 +2363,6 @@ char *getCookie(qhashtbl_t *cookies, char *cki) if (NULL != ck) ret = ck->value; - return ret; } @@ -4035,10 +4044,12 @@ T(c); // la = waitLoadAverage(la, loadAverageInc, simTimeOut); } free(c); + free(name); break; } + free(name); } - + freeSimList(sims); } free(first); } @@ -4233,6 +4244,7 @@ static int sessionValidate(reqData *Rd, inputForm *iF, inputValue *iV) I("Validating LINKY hashish %s", hashish); free(hashish); hashish = qhex_encode(t, sz); + free(t); linky = TRUE; } else @@ -6338,10 +6350,15 @@ static void cleanup(void) C("Caught signal, or quitting, cleaning up."); dbRequest **rq; - while (NULL != (rq = (dbRequest **) dbRequests->popfirst(dbRequests, NULL))) + if (dbRequests) { - dbFreeRequest(*rq); - free(rq); + while (NULL != (rq = (dbRequest **) dbRequests->popfirst(dbRequests, NULL))) + { + dbFreeRequest(*rq); + free(rq); + } + dbRequests->free(dbRequests); + dbRequests = NULL; } if (accountPages) @@ -6393,15 +6410,15 @@ static void cleanup(void) } HTMLfileCache->unlock(HTMLfileCache); HTMLfileCache->free(HTMLfileCache); + HTMLfileCache = NULL; } if (mimeTypes) mimeTypes->free(mimeTypes); mimeTypes = NULL; - if (dbRequests) dbRequests->free(dbRequests); - dbRequests = NULL; if (database) mysql_close(database); database = NULL; mysql_library_end(); - lua_close(L); + if (L) lua_close(L); + L = NULL; if (stats) { if (stats->stats) stats->stats->free(stats->stats); @@ -6409,6 +6426,7 @@ static void cleanup(void) stats = NULL; } if (configs) configs->free(configs); + configs = NULL; } @@ -6416,7 +6434,6 @@ void sledjchisl_main(void) { char *cmd = *toys.optargs; char *tmp; - gridStats *stats = NULL; struct stat statbuf; int status, result, i; void *vd; @@ -7158,7 +7175,7 @@ fcgiDone: // The sudo is only so that the session is owned by opensim, otherwise it's owned by whoever ran this script, which is a likely security hole. // After the session is created, we rely on the scRun directory to be group sticky, so that anyone in the opensim group can attach to the tmux socket. snprintf(toybuf, sizeof(toybuf), - "sudo -Hu %s %s %s/%s new-session -d -s %s -n '%s' \\; split-window -bhp 50 -t '%s:' bash -c './sledjchisl; cd %s; bash'", + "sudo -Hu %s %s %s/%s new-session -d -s %s -n '%s' \\; split-window -bhp 50 -t '%s:' bash -c '/usr/bin/valgrind --leak-check=full ./sledjchisl; cd %s; bash'", scUser, Tcmd, scRun, Tsocket, Tconsole, Ttab, Tconsole, scRoot); i = system(toybuf); if (!WIFEXITED(i)) @@ -7226,7 +7243,9 @@ fcgiDone: I("%s is done starting up.", name); la = waitLoadAverage(la, loadAverageInc, simTimeOut); } + free(nm); } + free(name); } } @@ -7247,6 +7266,8 @@ fcgiDone: { } + freeSimList(sims); + /* double sum; -- cgit v1.1