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.
This commit is contained in:
Olaf Bergmann committed 2021-05-25 10:25:00 +02:00
1 parent ead82c4049
commit 90537d143a
1 file changed
+1
+1
View File
@@ -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;
}