examples/libcoap_client : fix memory leakage on libcoap_client
This commit is to fix memoray leakage on libcoap_client
- TizenRT should free allocated memory by using free
- payload.s and optlist has not-freed memory so, fix them
@@ -1188,6 +1188,17 @@ int main(int argc, char **argv)
close_output();
coap_free_context(ctx);
+ /*
+ * free payload.s
+ * when cmdline_input function is used (e option), parameter s has allocated memory
+ */
+ if (payload.s) {
+ free(payload.s);
+ }
+
+ payload.s = NULL;
+ payload.length = 0;
+
/*
* deinitialize variables
* optlist : without initialize optlist, new option is appened to old option existed in optlist
@@ -1195,6 +1206,16 @@ int main(int argc, char **argv)
* ready : when NON message is continously sent to server, ready field should be deinitialized
* without deinitialization, it cannot enter select loop
*/
+
+ coap_list_t *next = NULL;
+
+ if (optlist) {
+ do {
+ next = optlist->next;
+ coap_delete(optlist);
+ optlist = next;
+ } while (optlist != NULL);
+ }
optlist = NULL;
ready = 0;
