From b3eacf2eacb1389e8020bc353a0221fab0c2d896 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Fri, 7 Aug 2020 20:07:09 +0100 Subject: [PATCH] net.c: memory leak in handle_request if error input coap_add_token() can error for multiple reasons when building the response PDU - but then the response PDU is not deleted on error if it exists. The PDU is now deleted on coap_add_token() error. --- src/net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/net.c b/src/net.c index ecdd1018ba..5a3fbf1a38 100644 --- a/src/net.c +++ b/src/net.c @@ -2363,10 +2363,11 @@ handle_request(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu } else { coap_delete_pdu(response); } - response = NULL; } else { coap_log(LOG_WARNING, "cannot generate response\r\n"); + coap_delete_pdu(response); } + response = NULL; } else { if (coap_string_equal(uri_path, &coap_default_uri_wellknown)) { /* request for .well-known/core */