bugID:19236743:[coap server]free send node while mutex is locked to avoid double free
@@ -397,13 +397,18 @@ static int CoAPRespMessage_handle(CoAPContext *context, NetworkAddr *remote, CoA
#ifndef COAP_OBSERVE_CLIENT_DISABLE
CoAPObsClient_add(ctx, message, remote, node);
#endif
+ if (!node->keep) {
+ if (NULL != node->message) {
+ coap_free(node->message);
+ }
+ coap_free(node);
+ COAP_DEBUG("The message needless keep, free it");
+ }
+
HAL_MutexUnlock(ctx->sendlist.list_mutex);
COAP_FLOW("Call the response message callback %p", handler);
handler(ctx, COAP_REQUEST_SUCCESS, message->user, remote, message);
} else {
- HAL_MutexUnlock(ctx->sendlist.list_mutex);
- }
-
if (!node->keep) {
if (NULL != node->message) {
coap_free(node->message);
@@ -411,6 +416,9 @@ static int CoAPRespMessage_handle(CoAPContext *context, NetworkAddr *remote, CoA
coap_free(node);
COAP_DEBUG("The message needless keep, free it");
}
+ HAL_MutexUnlock(ctx->sendlist.list_mutex);
+ }
+
} else {
HAL_MutexUnlock(ctx->sendlist.list_mutex);
#ifndef COAP_OBSERVE_CLIENT_DISABLE
