From 90537d143aad875d78ecc9186c6bc5eebe5d5de7 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Tue, 25 May 2021 10:25:00 +0200 Subject: [PATCH] resource.c: Fix memory leak in coap_add_observer() If no observer exists, a new cache key is created and storage for a new subscription may be allocated. If this fails, the newly created cache key must be released. This fixes CID 1504918. --- src/resource.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/resource.c b/src/resource.c index d6586ece..48d496a4 100644 --- a/src/resource.c +++ b/src/resource.c @@ -759,6 +759,7 @@ static const uint16_t cache_ignore_options[] = { COAP_OPTION_ETAG }; s = COAP_MALLOC_TYPE(subscription); if (!s) { + coap_delete_cache_key(cache_key); return NULL; }