-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Libcoap memory release, a missing functionality? A question. #1597
Comments
Thanks for raising this. There are the following storing of data functions which potentially have similar issues
I see no reason as to why these functions can have a new variant that also sets an optional call-back handler for releasing the information pointed to by app pointer. I think that a subsequent call to the same That said, in your case, if you are only doing this server side, then you can trap in the event call-back handler the event COAP_EVENT_SERVER_SESSION_DEL and release the data. See #839.. It is not so easy to do this on the client side as COAP_EVENT_SESSION_CLOSED / COAP_EVENT_SESSION_FAILED occur earlier in the session shutdown process. |
Thanks for your swift and detailed answer. Anyway, I am rather new with libcoap, so I do not feel confident that my libcoap overview is sufficient to propose detailed modifications. coap_session.h: Added:
coap_session.c: Added:
coap_net.c: in coap_free_context_lkd(): changed lines from:
into:
I leave any judgement of my changes to the libcoap author(s). There might be other/better/different ways of handling |
For the record, I am currently using libcoap version 4.3.5. And, let me emphasize: this is currently a question only.
In the struct coap_session_t exists a variable app which is intended to hold application-specific data.
I can set and get data using the functions
All this works well.
Here comes my issue:
My application needs to store several data items with the session, for this I use an application-defined
struct which is dynamically allocated using malloc(). coap_session_set_app_data() is used to give this to the session.
The problem I experience is when the application is terminated, when one or many sessions are still active.
When the context is released, everything is cared for, except the release of memory which is held by the
session through use of coap_session_set_app_data(). This memory will never be freed.
From my point-of-view I miss a callback function which is called when the context is released, such that
all allocated memory can be correctly released, i.e. also memory allocated at application level.
I my own "fork" of libcoap I have introduced a
typedef void (*coap_session_release_cbf_t)(coap_session_t* session);
which is called when iterating through sessions at the time of context release. Similarly, I have
void coap_session_set_release_cbf(coap_session_release_cbf_t cbf);
to set this callback function pointer from the application. By this the application will always have a way to
release any application defined memory.
This measure seems to solve my issues just fine.
So the question is: it this not a functionality missing in the current public version of libcoap???
Or... am i missing something I am not currently seeing?
The text was updated successfully, but these errors were encountered: