Module: kamailio Branch: master Commit: 73a288e14ec8f7a67662842140d5eb02819b7738 URL: https://github.com/kamailio/kamailio/commit/73a288e14ec8f7a67662842140d5eb02...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2017-07-28T10:30:19+02:00
janssonrpcc: couple of pkg free in case of errors
---
Modified: src/modules/janssonrpcc/janssonrpc_connect.c Modified: src/modules/janssonrpcc/janssonrpc_io.c
---
Diff: https://github.com/kamailio/kamailio/commit/73a288e14ec8f7a67662842140d5eb02... Patch: https://github.com/kamailio/kamailio/commit/73a288e14ec8f7a67662842140d5eb02...
---
diff --git a/src/modules/janssonrpcc/janssonrpc_connect.c b/src/modules/janssonrpcc/janssonrpc_connect.c index a65323d30a..83fd4530e8 100644 --- a/src/modules/janssonrpcc/janssonrpc_connect.c +++ b/src/modules/janssonrpcc/janssonrpc_connect.c @@ -111,14 +111,15 @@ typedef struct server_backoff_args {
void server_backoff_cb(int fd, short event, void *arg) { + unsigned int timeout; + server_backoff_args_t* a; + if(!arg) return;
- server_backoff_args_t* a = (server_backoff_args_t*)arg; - if(!a) - return; + a = (server_backoff_args_t*)arg;
- unsigned int timeout = a->timeout; + timeout = a->timeout;
/* exponential backoff */ if(timeout < 1) { diff --git a/src/modules/janssonrpcc/janssonrpc_io.c b/src/modules/janssonrpcc/janssonrpc_io.c index 018f03e977..4708a75a87 100644 --- a/src/modules/janssonrpcc/janssonrpc_io.c +++ b/src/modules/janssonrpcc/janssonrpc_io.c @@ -231,8 +231,10 @@ void fail_request(int code, jsonrpc_request_t* req, char* err_str)
end: if(freeme) free(freeme); - free_req_cmd(req->cmd); - free_request(req); + if(req) { + if(req->cmd) free_req_cmd(req->cmd); + free_request(req); + } }
void timeout_cb(int fd, short event, void *arg) @@ -354,13 +356,18 @@ void loadbalance_by_weight(jsonrpc_server_t** s,
int jsonrpc_send(str conn, jsonrpc_request_t* req, bool notify_only) { - char* json = (char*)json_dumps(req->payload, JSON_COMPACT); - - char* ns; + char* json = NULL; + bool sent = false; + char* ns = NULL; size_t bytes; + + json = (char*)json_dumps(req->payload, JSON_COMPACT); + if(json==NULL) { + LM_ERR("failed to do json dump for request payload\n"); + return -1; + } bytes = netstring_encode_new(&ns, json, (size_t)strlen(json));
- bool sent = false; jsonrpc_server_group_t* c_grp = NULL; if(global_server_group != NULL) c_grp = *global_server_group; @@ -426,7 +433,7 @@ int jsonrpc_send(str conn, jsonrpc_request_t* req, bool notify_only)
free_server_list(tried_servers); if(ns) pkg_free(ns); - if(json) free(json); + free(json);
if (sent) { if (notify_only == true) { // free the request if using janssonrpc_notification function @@ -520,6 +527,7 @@ void cmd_pipe_cb(int fd, short event, void *arg) if(freeme) free(freeme); if(error) json_decref(error); free_req_cmd(req_cmd); + if(req) pkg_free(req); goto end; }
@@ -740,9 +748,6 @@ void bev_read_cb(struct bufferevent* bev, void* arg) case NETSTRING_ERROR_NO_LENGTH: msg = "missing length field"; break; - case NETSTRING_INCOMPLETE: - msg = "incomplete"; - break; default: ERR("bad netstring: unknown error (%d)\n", retval); goto reconnect;