mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-05 09:22:54 +03:00
endpoint->hello information memory leak when coap_free_endpoint() called
Information set up in the pseudo session held in endpoint->hello is not freed
off when coap_free_endpoint() is called.
A solution is to split coap_session_free() into two parts with
coap_session_free() calling a new function coap_session_mfree().
Then coap_mfree_endpoint() can call coap_session_mfree() to free off the
endpoint specific hello information.
Makefile.am
Add coap_mfree_endpoint and coap_session_mfree to the CTAGS_IGNORE list.
libcoap-2.{map|sym}
Remove coap_mfree_endpoint as it is not a public function
include/coap2/coap_session.h
Add in new coap_session_mfree() function definition
src/coap_io.c
Call coap_session_mfree() from within coap_mfree_endpoint()
src/coap_session.c
Move some of the functionality out of coap_session_free() into a new
function coap_session_mfree() and call coap_session_mfree().
This commit is contained in:
1 parent
4626dea3a6
commit
8dcdbfb477
6 files changed
+21
-15
No files matched your search
@@ -157,8 +157,10 @@ coap_dtls_send \
|
||||
coap_dtls_session_update_mtu \
|
||||
coap_dtls_startup \
|
||||
coap_endpoint_new_dtls_session \
|
||||
coap_mfree_endpoint \
|
||||
coap_packet_extract_pbuf \
|
||||
coap_pdu_from_pbuf \
|
||||
coap_session_mfree \
|
||||
coap_socket_accept_tcp \
|
||||
coap_socket_bind_tcp \
|
||||
coap_socket_bind_udp \
|
||||
|
||||
@@ -368,6 +368,7 @@ coap_session_t *coap_session_get_by_peer(struct coap_context_t *ctx,
|
||||
const struct coap_address_t *remote_addr, int ifindex);
|
||||
|
||||
void coap_session_free(coap_session_t *session);
|
||||
void coap_session_mfree(coap_session_t *session);
|
||||
|
||||
/**
|
||||
* @defgroup cc Rate Control
|
||||
|
||||
@@ -78,7 +78,6 @@ global:
|
||||
coap_malloc_endpoint;
|
||||
coap_malloc_type;
|
||||
coap_memory_init;
|
||||
coap_mfree_endpoint;
|
||||
coap_network_read;
|
||||
coap_network_send;
|
||||
coap_new_client_session;
|
||||
|
||||
@@ -76,7 +76,6 @@ coap_log_impl
|
||||
coap_malloc_endpoint
|
||||
coap_malloc_type
|
||||
coap_memory_init
|
||||
coap_mfree_endpoint
|
||||
coap_network_read
|
||||
coap_network_send
|
||||
coap_new_client_session
|
||||
|
||||
@@ -94,6 +94,7 @@ struct coap_endpoint_t *
|
||||
void
|
||||
coap_mfree_endpoint(struct coap_endpoint_t *ep) {
|
||||
ep_initialized = 0;
|
||||
coap_session_mfree(&ep->hello);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -183,6 +184,7 @@ struct coap_endpoint_t *
|
||||
|
||||
void
|
||||
coap_mfree_endpoint(struct coap_endpoint_t *ep) {
|
||||
coap_session_mfree(&ep->hello);
|
||||
coap_free_type(COAP_ENDPOINT, ep);
|
||||
}
|
||||
|
||||
|
||||
+16
-13
@@ -144,14 +144,9 @@ coap_make_session(coap_proto_t proto, coap_session_type_t type,
|
||||
return session;
|
||||
}
|
||||
|
||||
void coap_session_free(coap_session_t *session) {
|
||||
void coap_session_mfree(coap_session_t *session) {
|
||||
coap_queue_t *q, *tmp;
|
||||
|
||||
if (!session)
|
||||
return;
|
||||
assert(session->ref == 0);
|
||||
if (session->ref)
|
||||
return;
|
||||
if (session->partial_pdu)
|
||||
coap_delete_pdu(session->partial_pdu);
|
||||
if (session->proto == COAP_PROTO_DTLS)
|
||||
@@ -160,13 +155,6 @@ void coap_session_free(coap_session_t *session) {
|
||||
coap_tls_free_session(session);
|
||||
if (session->sock.flags != COAP_SOCKET_EMPTY)
|
||||
coap_socket_close(&session->sock);
|
||||
if (session->endpoint) {
|
||||
if (session->endpoint->sessions)
|
||||
LL_DELETE(session->endpoint->sessions, session);
|
||||
} else if (session->context) {
|
||||
if (session->context->sessions)
|
||||
LL_DELETE(session->context->sessions, session);
|
||||
}
|
||||
if (session->psk_identity)
|
||||
coap_free(session->psk_identity);
|
||||
if (session->psk_key)
|
||||
@@ -177,7 +165,22 @@ void coap_session_free(coap_session_t *session) {
|
||||
session->context->nack_handler(session->context, session, q->pdu, session->proto == COAP_PROTO_DTLS ? COAP_NACK_TLS_FAILED : COAP_NACK_NOT_DELIVERABLE, q->id);
|
||||
coap_delete_node(q);
|
||||
}
|
||||
}
|
||||
|
||||
void coap_session_free(coap_session_t *session) {
|
||||
if (!session)
|
||||
return;
|
||||
assert(session->ref == 0);
|
||||
if (session->ref)
|
||||
return;
|
||||
if (session->endpoint) {
|
||||
if (session->endpoint->sessions)
|
||||
LL_DELETE(session->endpoint->sessions, session);
|
||||
} else if (session->context) {
|
||||
if (session->context->sessions)
|
||||
LL_DELETE(session->context->sessions, session);
|
||||
}
|
||||
coap_session_mfree(session);
|
||||
coap_log(LOG_DEBUG, "***%s: session closed\n", coap_session_str(session));
|
||||
|
||||
coap_free_type(COAP_SESSION, session);
|
||||
|
||||
Reference in new issue
Block a user