Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
coap: When a client is observing a server, a block is always leaked
Browse files Browse the repository at this point in the history
When a client starts to observe a server, a struct was allocated
to keep some context data. When client asks to be unobserved from the
server, or if the client is terminated, this block leaks.

With this pathc sol-coap will always call reply_cb when a client is
unobserved, as it is done when timeout is reached, so users can free
memory.

One way to check this bahaviour is running the light-server +
light-client sample located in src/samples/flow/oic/ and terminating the
client execution.

Valgrind tells us this:

==2586== 40 bytes in 1 blocks are definitely lost in loss record 20 of 31
==2586==    at 0x4C28C10: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2586==    by 0x54128E1: sol_util_memdup (in /home/otavio/local/soletta/lib/libsoletta.so.0.0.1)
==2586==    by 0x53A133A: _resource_request (in /home/otavio/local/soletta/lib/libsoletta.so.0.0.1)
==2586==    by 0x53A1D7C: sol_oic_client_resource_set_observable (in /home/otavio/local/soletta/lib/libsoletta.so.0.0.1)
==2586==    by 0xCBAD915: found_resource (in /home/otavio/local/soletta/lib/soletta/modules/flow/oic.so)
==2586==    by 0x53A05E1: _iterate_over_resource_reply_payload (in /home/otavio/local/soletta/lib/libsoletta.so.0.0.1)
==2586==    by 0x53A08FE: _find_resource_reply_cb (in /home/otavio/local/soletta/lib/libsoletta.so.0.0.1)
==2586==    by 0x5391032: respond_packet (in /home/otavio/local/soletta/lib/libsoletta.so.0.0.1)
==2586==    by 0x5391413: on_can_read (in /home/otavio/local/soletta/lib/libsoletta.so.0.0.1)
==2586==    by 0x53A41F2: on_socket_read (in /home/otavio/local/soletta/lib/libsoletta.so.0.0.1)
==2586==    by 0x538391E: fd_process (in /home/otavio/local/soletta/lib/libsoletta.so.0.0.1)
==2586==    by 0x53839FE: sol_mainloop_impl_iter (in /home/otavio/local/soletta/lib/libsoletta.so.0.0.1)
==2586==
  • Loading branch information
Otavio Pontes committed Dec 2, 2015
1 parent 3556363 commit 39a60de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/lib/comms/sol-coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ sol_coap_server_destroy(struct sol_coap_server *server)

SOL_PTR_VECTOR_FOREACH_REVERSE_IDX (&server->pending, reply, i) {
sol_ptr_vector_del(&server->pending, i);
reply->cb(server, NULL, NULL, (void *)reply->data);
pending_reply_free(reply);
}

Expand Down Expand Up @@ -1600,6 +1601,7 @@ sol_coap_unobserve_server(struct sol_coap_server *server, const struct sol_netwo
if (!match_observe_reply(reply, token, tkl))
continue;

reply->cb(server, NULL, NULL, (void *)reply->data);
sol_ptr_vector_del(&server->pending, i);

r = send_unobserve_packet(server, cliaddr, reply->path, token, tkl);
Expand Down
8 changes: 6 additions & 2 deletions src/lib/comms/sol-oic-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,10 @@ _resource_request_cb(struct sol_coap_server *server,

if (!ctx->cb)
return false;
if (!req || !cliaddr)
if (!req || !cliaddr) {
free(data);
return false;
}
if (!_pkt_has_same_token(req, ctx->token))
return true;
if (!sol_oic_pkt_has_cbor_content(req))
Expand Down Expand Up @@ -813,7 +815,9 @@ _one_shot_resource_request_cb(struct sol_coap_server *server,
struct sol_coap_packet *req, const struct sol_network_link_addr *cliaddr,
void *data)
{
_resource_request_cb(server, req, cliaddr, data);

if (req && cliaddr)
_resource_request_cb(server, req, cliaddr, data);

free(data);
return false;
Expand Down

0 comments on commit 39a60de

Please sign in to comment.