From 710de1c93422423b2ee1e959b7c1e88a1949038b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Wed, 5 Jun 2024 19:13:09 +0200 Subject: [PATCH] fixup! nanocoap/sock: fix context release --- sys/net/application_layer/nanocoap/sock.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/sys/net/application_layer/nanocoap/sock.c b/sys/net/application_layer/nanocoap/sock.c index ed2a842842ec3..6f47ecb8c524c 100644 --- a/sys/net/application_layer/nanocoap/sock.c +++ b/sys/net/application_layer/nanocoap/sock.c @@ -55,7 +55,6 @@ enum { STATE_REQUEST_SEND, /**< request was just sent or will be sent again */ STATE_STOP_RETRANSMIT, /**< stop retransmissions due to a matching empty ACK */ STATE_WAIT_RESPONSE, /**< waiting for a response */ - STATE_RESPONSE_OK, /**< valid response was received */ }; typedef struct { @@ -314,26 +313,22 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt, case COAP_TYPE_RST: case COAP_TYPE_CON: case COAP_TYPE_NON: - state = STATE_RESPONSE_OK; if (coap_get_type(pkt) == COAP_TYPE_RST) { /* think about whether cb should be called on RST as well */ res = -EBADMSG; + goto release; + } + if (coap_get_type(pkt) == COAP_TYPE_CON) { + _send_ack(sock, pkt); + } + if (cb) { + res = cb(arg, pkt); } else { - if (coap_get_type(pkt) == COAP_TYPE_CON) { - _send_ack(sock, pkt); - } - if (cb) { - res = cb(arg, pkt); - } - else { - res = _get_error(pkt); - } + res = _get_error(pkt); } - continue; + goto release; } - case STATE_RESPONSE_OK: /* response received, release ctx */ - goto release; } }