From d4a7647ac13c74e89d83248687e755355bf14c29 Mon Sep 17 00:00:00 2001 From: onefang Date: Wed, 7 Jul 2021 09:06:54 +1000 Subject: Various memory freeing stuff. --- src/sledjchisl/sledjchisl.c | 49 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index f395703..8ab41ab 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -820,8 +820,7 @@ simList *getSims() { char *sim = ourSims->sims[i], *name = xmprintf("%s/config/%s", scRoot, sim); qlisttbl_t *ini; - simData *simd = xmalloc(sizeof(simData)); - + simData *simd = xzalloc(sizeof(simData)); struct dirtree *new = dirtree_add_node(0, name, 0); free(name); @@ -887,10 +886,12 @@ ourSims->tbl->put(ourSims->tbl, sim, ini, sizeof(qlisttbl_t)); } free(cmd); } + free(ini); + free(newPath); + free(path); } - free(newPath); - free(path); - + else + free(name); if (-1 != fd) { @@ -901,6 +902,7 @@ ourSims->tbl->put(ourSims->tbl, sim, ini, sizeof(qlisttbl_t)); free(tnm); } + free(simd); } if (-1 != fd) @@ -914,7 +916,6 @@ ourSims->tbl->put(ourSims->tbl, sim, ini, sizeof(qlisttbl_t)); } free(file); - return ourSims; } @@ -941,16 +942,18 @@ void freeSimList(simList *sims) if (NULL != simd) { free(simd->name); + free(simd->tab); free(simd->UUID); free(simd->regionType); -// free(simd->estate); -// free(simd->owner); + free(simd->estate); + free(simd->owner); free(simd); } // TODO - this leaks memory, but it's a bug in qLibc. Send the bug fix upstream. // It either leaks, or frees twice. Pffft // ini->clear(ini); // ini->free(ini); +// free(ini); ; } @@ -961,6 +964,30 @@ void freeSimList(simList *sims) sims->tbl->unlock(sims->tbl); sims->tbl->free(sims->tbl); + memset((void*) &obj, 0, sizeof(obj)); // start from the minimum. + sims->byTab->lock(sims->byTab); + while (sims->byTab->getnext(sims->byTab, &obj, false) == true) + { + char *name = qmemdup(obj.name, obj.namesize); // keep the name + size_t namesize = obj.namesize; // for removal argument + qlisttbl_t *ini = (qlisttbl_t *) obj.data; + if (NULL != ini) + { +// TODO - this leaks memory, but it's a bug in qLibc. Send the bug fix upstream. +// It either leaks, or frees twice. Pffft +// ini->clear(ini); +// ini->free(ini); +// free(ini); + ; + } + + sims->byTab->remove_by_obj(sims->byTab, obj.name, obj.namesize); // remove + obj = sims->byTab->find_nearest(sims->byTab, name, namesize, false); // rewind one step back + free(name); // clean up + } + sims->byTab->unlock(sims->byTab); + sims->byTab->free(sims->byTab); + free(sims); } @@ -1006,6 +1033,8 @@ int checkSimIsRunning(char *sim) else d("checkSimIsRunning(%s) has PID %s, which is actually running.", sim, pid); } +// TODO - WTF? +// free(path); } } free(pid); @@ -6871,6 +6900,7 @@ jit library is loaded or the JIT compiler will not be activated. // Don't want it in the path. // Could put the .dlls into lib. Most of the rest is config files or common assets. // Or just slowly migrate opensim stuff to FHS. +// TODO - free these. Though valgrind isn't bitching about them. scBin = xmprintf("%s%s/bin", slsh, scRoot); scEtc = xmprintf("%s%s/etc", slsh, scRoot); scLib = xmprintf("%s%s/lib", slsh, scRoot); @@ -7640,6 +7670,8 @@ sims = -- Note these are .shini / tmux tab short names. I("Not waiting for %s to finish starting up.", name); count++; } + free(newPath); + free(path); } break; } @@ -7813,6 +7845,7 @@ nextSim: finished: freeSimList(ourSims); + ourSims = NULL; // An example of calling a toy directly. // printf("\n\n"); -- cgit v1.1