Skip to content

Commit

Permalink
janssonrpc-c: fix memory leak when using janssonrpc_notification
Browse files Browse the repository at this point in the history
(cherry picked from commit c6b38e4)
  • Loading branch information
Emmanuel Schmidbauer authored and miconda committed Nov 2, 2016
1 parent a53c91c commit 4fb274c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions modules/janssonrpc-c/janssonrpc_io.c
Expand Up @@ -428,15 +428,18 @@ int jsonrpc_send(str conn, jsonrpc_request_t* req, bool notify_only)
if(ns) pkg_free(ns);
if(json) free(json);

if (sent && notify_only == false) {

const struct timeval tv = ms_to_tv(req->timeout);
if (sent) {
if (notify_only == true) { // free the request if using janssonrpc_notification function
free_request(req);
} else {
const struct timeval tv = ms_to_tv(req->timeout);

req->timeout_ev = evtimer_new(global_ev_base, timeout_cb, (void*)req);
if(event_add(req->timeout_ev, &tv)<0) {
ERR("event_add failed while setting request timer (%s).",
strerror(errno));
return -1;
req->timeout_ev = evtimer_new(global_ev_base, timeout_cb, (void*)req);
if(event_add(req->timeout_ev, &tv)<0) {
ERR("event_add failed while setting request timer (%s).",
strerror(errno));
return -1;
}
}
}

Expand Down

0 comments on commit 4fb274c

Please sign in to comment.