From 7dea55099f776ca5f9a432c9c547c601acad3cb6 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Wed, 6 Apr 2016 12:43:27 +0200 Subject: [PATCH] resource.c: bugfix: Memory leak from hash table The function coap_delete_all_resources() did not free the hash buckets created by HASH_ADD. Thus, the iterator must call HASH_DELETE to free the allocated storage. This bug has been discovered by Jean-Michel Julien who also provided this fix. See [1] for more information. [1] https://sourceforge.net/p/libcoap/mailman/message/34994226/ --- src/resource.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/resource.c b/src/resource.c index 0aa12831..61ab87ca 100644 --- a/src/resource.c +++ b/src/resource.c @@ -457,6 +457,7 @@ coap_delete_all_resources(coap_context_t *context) { LL_FOREACH_SAFE(context->resources, res, rtmp) { #else HASH_ITER(hh, context->resources, res, rtmp) { + HASH_DELETE(hh, context->resources, res); #endif coap_free_resource(res); }