Skip to content

Commit

Permalink
Coverity: Fix 1588815 and 1588818
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed May 28, 2024
1 parent cb20c48 commit 520f054
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/coap_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -3422,7 +3422,7 @@ handle_request(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu
coap_lock_callback_release(context,
h(resource, session, pdu, query, response),
/* context is being freed off */
return);
goto finish);

/* Check validity of response code */
if (!coap_check_code_class(session, response)) {
Expand Down Expand Up @@ -3569,9 +3569,9 @@ handle_request(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu
}
#endif /* COAP_Q_BLOCK_SUPPORT */

#if COAP_Q_BLOCK_SUPPORT
#if COAP_Q_BLOCK_SUPPORT || COAP_THREADSAFE
finish:
#endif /* COAP_Q_BLOCK_SUPPORT */
#endif /* COAP_Q_BLOCK_SUPPORT || COAP_THREAD_SAFE */
coap_delete_string(uri_path);
return;

Expand Down
48 changes: 25 additions & 23 deletions src/coap_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1997,34 +1997,36 @@ coap_free_endpoint_lkd(coap_endpoint_t *ep) {
if (ep) {
coap_session_t *session, *rtmp;

if (ep->context)
if (ep->context) {
/* If fully allocated and inserted */
coap_lock_check_locked(ep->context);
SESSIONS_ITER_SAFE(ep->sessions, session, rtmp) {
assert(session->ref == 0);
if (session->ref == 0) {
coap_handle_event_lkd(ep->context, COAP_EVENT_SERVER_SESSION_DEL, session);
coap_session_free(session);
SESSIONS_ITER_SAFE(ep->sessions, session, rtmp) {
assert(session->ref == 0);
if (session->ref == 0) {
coap_handle_event_lkd(ep->context, COAP_EVENT_SERVER_SESSION_DEL, session);
coap_session_free(session);
}
}
}
if (coap_netif_available_ep(ep)) {
/*
* ep->sock.endpoint is set in coap_new_endpoint().
* ep->sock.session is never set.
*
* session->sock.session is set for both clients and servers (when a
* new session is accepted), but does not affect the endpoint.
*
* So, it is safe to call coap_netif_close_ep() after all the sessions
* have been freed above as we are only working with the endpoint sock.
*/
if (coap_netif_available_ep(ep)) {
/*
* ep->sock.endpoint is set in coap_new_endpoint().
* ep->sock.session is never set.
*
* session->sock.session is set for both clients and servers (when a
* new session is accepted), but does not affect the endpoint.
*
* So, it is safe to call coap_netif_close_ep() after all the sessions
* have been freed above as we are only working with the endpoint sock.
*/
#ifdef COAP_EPOLL_SUPPORT
assert(ep->sock.session == NULL);
assert(ep->sock.session == NULL);
#endif /* COAP_EPOLL_SUPPORT */
coap_netif_close_ep(ep);
}
coap_netif_close_ep(ep);
}

if (ep->context && ep->context->endpoint) {
LL_DELETE(ep->context->endpoint, ep);
if (ep->context->endpoint) {
LL_DELETE(ep->context->endpoint, ep);
}
}
coap_mfree_endpoint(ep);
}
Expand Down

0 comments on commit 520f054

Please sign in to comment.