netutils/libcoap : patch to prevent memory leakage caused by observers
authorJin-Seong Kim <jseong82.kim@samsung.com>
Tue, 18 Jul 2017 05:32:00 +0000 (14:32 +0900)
committerEunBong Song <eunb.song@samsung.com>
Wed, 30 Aug 2017 04:15:45 +0000 (21:15 -0700)
This commit is patch to prevent memory leakage caused by observers
 - there is no routine to free observers for libcoap-server
 - remained observers in a resource can cause memory leakage

Change-Id: Ib2aefc9cd5f9572f5170fc96f0f832e02692dfc9
Signed-off-by: Jin-Seong Kim <jseong82.kim@samsung.com>
apps/netutils/libcoap/net.c

index 876d57e..1bfc400 100644 (file)
@@ -493,6 +493,16 @@ void coap_free_context(coap_context_t *context)
 #else
        HASH_ITER(hh, context->resources, res, rtmp) {
 #endif
+/* To prevent memory leakage due to remained subscribers */
+#ifndef WITHOUT_OBSERVE
+               coap_subscription_t *s = NULL;
+               for (s = list_head(res->subscribers); s; s = list_item_next(s)) {
+                       if (s) {
+                               list_remove(res->subscribers, s);
+                               coap_free(s);
+                       }
+               }
+#endif
                coap_delete_resource(context, res->key);
        }
 #endif /* WITH_POSIX || WITH_LWIP */