example of integration with websocket in C
[src/app-framework-binder.git] / src / session.c
index 667738c..326b16a 100644 (file)
@@ -276,6 +276,7 @@ void ctxClientUnref(struct AFB_clientCtx *clientCtx)
                --clientCtx->refcount;
                        if (clientCtx->refcount == 0 && clientCtx->uuid[0] == 0) {
                        ctxStoreDel (clientCtx);
+                       free(clientCtx);
                }
        }
 }
@@ -284,8 +285,16 @@ 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);
+                       if (clientCtx->refcount == 0) {
+                       ctxStoreDel (clientCtx);
+                       free(clientCtx);
+               }
+       }
 }
 
 // Sample Generic Ping Debug API