BugID:19948586: Fix Coredump caused by CoAP.
@@ -390,6 +390,7 @@ static int CoAPRespMessage_handle(CoAPContext *context, NetworkAddr *remote, CoA
if (found && NULL != node) {
message->user = node->user;
+ CoAPSendMsgHandler handler = NULL;
/* TODO: comment it */
/*
if (COAP_MSG_CODE_400_BAD_REQUEST <= message->header.code) {
@@ -399,22 +400,12 @@ static int CoAPRespMessage_handle(CoAPContext *context, NetworkAddr *remote, CoA
}
*/
if (NULL != node->handler) {
- CoAPSendMsgHandler handler = node->handler;
+ handler = node->handler;
#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 {
+ }
if (!node->keep) {
if (NULL != node->message) {
coap_free(node->message);
@@ -423,8 +414,8 @@ static int CoAPRespMessage_handle(CoAPContext *context, NetworkAddr *remote, CoA
COAP_DEBUG("The message needless keep, free it");
}
HAL_MutexUnlock(ctx->sendlist.list_mutex);
- }
+ if (handler) handler(ctx, COAP_REQUEST_SUCCESS, message->user, remote, message);
} else {
HAL_MutexUnlock(ctx->sendlist.list_mutex);
#ifndef COAP_OBSERVE_CLIENT_DISABLE
