From 80b2bef1b1c4445ad99f5f49304fd96a4eed78b6 Mon Sep 17 00:00:00 2001 From: LewixLiu Date: Tue, 28 May 2019 15:57:47 +0800 Subject: [PATCH 1/2] Correct the copy address direction --- include/coap2/coap_io.h | 3 --- libcoap-2.map | 1 - libcoap-2.sym | 1 - src/coap_io.c | 5 ----- src/net.c | 3 ++- 5 files changed, 2 insertions(+), 11 deletions(-) diff --git a/include/coap2/coap_io.h b/include/coap2/coap_io.h index cf6453ce..1854501b 100644 --- a/include/coap2/coap_io.h +++ b/include/coap2/coap_io.h @@ -164,9 +164,6 @@ void coap_packet_get_memmapped(struct coap_packet_t *packet, unsigned char **address, size_t *length); -void coap_packet_set_addr( struct coap_packet_t *packet, const coap_address_t *src, - const coap_address_t *dst ); - #ifdef WITH_LWIP /** * Get the pbuf of a packet. The caller takes over responsibility for freeing diff --git a/libcoap-2.map b/libcoap-2.map index 5155cfe7..901929ba 100644 --- a/libcoap-2.map +++ b/libcoap-2.map @@ -112,7 +112,6 @@ global: coap_package_name; coap_package_version; coap_packet_get_memmapped; - coap_packet_set_addr; coap_pdu_clear; coap_pdu_encode_header; coap_pdu_init; diff --git a/libcoap-2.sym b/libcoap-2.sym index 69bef838..1c92ed61 100644 --- a/libcoap-2.sym +++ b/libcoap-2.sym @@ -110,7 +110,6 @@ coap_opt_value coap_package_name coap_package_version coap_packet_get_memmapped -coap_packet_set_addr coap_pdu_clear coap_pdu_encode_header coap_pdu_init diff --git a/src/coap_io.c b/src/coap_io.c index 9b385782..9eefb062 100644 --- a/src/coap_io.c +++ b/src/coap_io.c @@ -919,11 +919,6 @@ coap_packet_get_memmapped(coap_packet_t *packet, unsigned char **address, size_t *length = packet->length; } -void coap_packet_set_addr(coap_packet_t *packet, const coap_address_t *src, const coap_address_t *dst) { - coap_address_copy(&packet->src, src); - coap_address_copy(&packet->dst, dst); -} - ssize_t coap_network_read(coap_socket_t *sock, coap_packet_t *packet) { ssize_t len = -1; diff --git a/src/net.c b/src/net.c index 3e2bcc60..13481543 100644 --- a/src/net.c +++ b/src/net.c @@ -1147,7 +1147,8 @@ coap_read_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now) coap_log(LOG_DEBUG, "* %s: received %zd bytes\n", coap_session_str(session), bytes_read); session->last_rx_tx = now; - coap_packet_set_addr(packet, &session->remote_addr, &session->local_addr); + coap_address_copy(&session->remote_addr, &packet->src); + coap_address_copy(&session->local_addr, &packet->dst); coap_handle_dgram_for_proto(ctx, session, packet); } } else { From b51125772495abf6c8326992add3514afc405db3 Mon Sep 17 00:00:00 2001 From: LewixLiu Date: Tue, 28 May 2019 16:00:30 +0800 Subject: [PATCH 2/2] Remove endpoint from context list when free --- src/coap_session.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coap_session.c b/src/coap_session.c index 550efc97..82ed6aff 100644 --- a/src/coap_session.c +++ b/src/coap_session.c @@ -946,6 +946,9 @@ coap_free_endpoint(coap_endpoint_t *ep) { } } + if (ep->context) { + LL_DELETE(ep->context->endpoint, ep); + } coap_mfree_endpoint(ep); } }