summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-05-11 17:42:49 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-05-11 17:42:49 +0200
commitf83af86907f072b8d58bc84acfb431682a9e3080 (patch)
treed900bbd126c067d04d0f3d9382cd56bd510f04aa
parent0b876c0f97a7c8458c22e768d1edf043e92a19e0 (diff)
fixup session memory leak
Change-Id: I49ed17a3818be6107c46ce17533761858d99f735 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/session.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/session.c b/src/session.c
index 667738c4..22e50cfc 100644
--- a/src/session.c
+++ b/src/session.c
@@ -197,10 +197,11 @@ static void ctxStoreCleanUp (time_t now)
// Loop on Sessions Table and remove anything that is older than timeout
for (idx=0; idx < sessions.max; idx++) {
- ctx = sessions.store[idx];
+ ctx = ctxClientAddRef(sessions.store[idx]);
if (ctx != NULL && ctxStoreTooOld(ctx, now)) {
ctxClientClose (ctx);
}
+ ctxClientUnref(ctx);
}
}
@@ -276,6 +277,7 @@ void ctxClientUnref(struct AFB_clientCtx *clientCtx)
--clientCtx->refcount;
if (clientCtx->refcount == 0 && clientCtx->uuid[0] == 0) {
ctxStoreDel (clientCtx);
+ free(clientCtx);
}
}
}
@@ -284,8 +286,12 @@ void ctxClientUnref(struct AFB_clientCtx *clientCtx)
void ctxClientClose (struct AFB_clientCtx *clientCtx)
{
assert(clientCtx != NULL);
- ctxUuidFreeCB (clientCtx);
- clientCtx->uuid[0] = 0;
+ if (clientCtx->uuid[0] != 0) {
+ clientCtx->uuid[0] = 0;
+ ctxUuidFreeCB (clientCtx);
+ while(clientCtx->listeners != NULL)
+ ctxClientEventListenerRemove(clientCtx, clientCtx->listeners->listener);
+ }
}
// Sample Generic Ping Debug API