Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[tinydtls-dev] Possible memory leak with netq_malloc_node

Hello,

I have been playing around with the tinydtls lib a bit lately and during testing I have found that (over time) quite a bit of memory is being leaked. In particular when running over networks with high packet loss. After analyzing it a little bit I found that the number of calls to netq_malloc_node and netq_free_node does not always match. 

In particular I found that sometimes when sending the Client Hello a node would be allocated and then never released.
In dtls_send_multi() a node is added to the ctx->sendqueue:

netq_t *n = netq_node_new(overall_len);
netq_insert_node(&ctx->sendqueue, n)

If I understand things correctly, it should be removed in dtls_stop_retransmission()? But during these cases it was not called and I am not sure why.

Instead (for testing) I added the following in the void dtls_free_context() function just before free_context() at the end:

if (ctx->sendqueue != NULL) {
netq_delete_all(&ctx->sendqueue);
}

After testing this for a while I can now see that on every occasion where a memory leak previously would have been generated the memory was now properly released. I do realize, however, that this might not be the proper way to fix this as I don't know what the underlying cause is. Either that or I made a mistake during the implementation...? I am sure though that every call to dtls_new_context() and dtls_connect() is properly followed by a dtls_close() and dtls_free_context(). Am I missing something?

/Anton

Back to the top