diff --git a/examples/coap-server.c b/examples/coap-server.c index 57665a65fc..7835d3c367 100644 --- a/examples/coap-server.c +++ b/examples/coap-server.c @@ -994,7 +994,7 @@ hnd_proxy_uri(coap_resource_t *resource COAP_UNUSED, size_t total; coap_binary_t *body_data = NULL; const uint8_t *data; - coap_pdu_t *pdu; + coap_pdu_t *pdu = NULL; coap_optlist_t *optlist = NULL; coap_opt_t *option; coap_bin_const_t token = coap_pdu_get_token(request); @@ -1093,7 +1093,6 @@ hnd_proxy_uri(coap_resource_t *resource COAP_UNUSED, if (!coap_add_token(pdu, token.length, token.s)) { coap_log_debug("cannot add token to proxy request\n"); coap_pdu_set_code(response, COAP_RESPONSE_CODE_INTERNAL_ERROR); - coap_delete_pdu(pdu); goto cleanup; } @@ -1166,6 +1165,7 @@ hnd_proxy_uri(coap_resource_t *resource COAP_UNUSED, * Do not update with response code (hence empty ACK) as will be sending * separate response when response comes back from upstream server */ + pdu = NULL; goto cleanup; } else { /* TODO http & https */ @@ -1175,6 +1175,7 @@ hnd_proxy_uri(coap_resource_t *resource COAP_UNUSED, coap_delete_string(uri_path); coap_delete_string(uri_query); coap_delete_binary(body_data); + coap_delete_pdu(pdu); } #endif /* SERVER_CAN_PROXY */ diff --git a/src/coap_block.c b/src/coap_block.c index 497cad919f..bc0fc3e7cf 100644 --- a/src/coap_block.c +++ b/src/coap_block.c @@ -3675,6 +3675,7 @@ coap_handle_response_get_block(coap_context_t *context, STATE_TOKEN_BASE(coap_decode_var_bytes8(rcvd->actual_token.s, rcvd->actual_token.length)); + coap_lock_check_locked(context); memset(&block, 0, sizeof(block)); #if COAP_Q_BLOCK_SUPPORT memset(&qblock, 0, sizeof(qblock)); diff --git a/src/coap_net.c b/src/coap_net.c index b1323db45e..91f62e78b5 100644 --- a/src/coap_net.c +++ b/src/coap_net.c @@ -585,7 +585,7 @@ coap_new_context(const coap_address_t *listen_addr) { memset(c, 0, sizeof(coap_context_t)); coap_lock_init(c); - coap_lock_lock(c, return NULL); + coap_lock_lock(c, coap_free_type(COAP_CONTEXT, c); return NULL); #ifdef COAP_EPOLL_SUPPORT c->epfd = epoll_create1(0); if (c->epfd == -1) { diff --git a/src/coap_resource.c b/src/coap_resource.c index ea06d6bfcc..e10cd5a7d0 100644 --- a/src/coap_resource.c +++ b/src/coap_resource.c @@ -1075,6 +1075,8 @@ coap_notify_observers(coap_context_t *context, coap_resource_t *r, coap_tick_t now; coap_session_t *obs_session; + coap_lock_check_locked(context); + if (r->observable && (r->dirty || r->partiallydirty)) { r->partiallydirty = 0;