netutils/libcoap : patch to prevent memory leakage caused by observers
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
@@ -492,6 +492,16 @@ void coap_free_context(coap_context_t *context)
LL_FOREACH(context->resources, res) {
#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);
}
