From 6fd3a24a43de602ac7b22a391a761beb107cf870 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Fri, 20 Sep 2019 05:36:05 +0800 Subject: [PATCH] [coap] add message free on error in Cli::CoapSecure::DefaultHandler (#4193) --- src/cli/cli_coap_secure.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cli/cli_coap_secure.cpp b/src/cli/cli_coap_secure.cpp index 7c0f9ad7d..a7d669cd9 100644 --- a/src/cli/cli_coap_secure.cpp +++ b/src/cli/cli_coap_secure.cpp @@ -558,8 +558,8 @@ void CoapSecure::DefaultHandler(void *aContext, otMessage *aMessage, const otMes void CoapSecure::DefaultHandler(otMessage *aMessage, const otMessageInfo *aMessageInfo) { - otError error = OT_ERROR_NONE; - otMessage *responseMessage; + otError error = OT_ERROR_NONE; + otMessage *responseMessage = NULL; if ((otCoapMessageGetType(aMessage) == OT_COAP_TYPE_CONFIRMABLE) || (otCoapMessageGetCode(aMessage) == OT_COAP_CODE_GET)) @@ -576,7 +576,10 @@ void CoapSecure::DefaultHandler(otMessage *aMessage, const otMessageInfo *aMessa } exit: - return; + if (error != OT_ERROR_NONE && responseMessage != NULL) + { + otMessageFree(responseMessage); + } } #endif // CLI_COAP_SECURE_USE_COAP_DEFAULT_HANDLER