Skip to content

Commit

Permalink
janssonrpcc: couple of pkg free in case of errors
Browse files Browse the repository at this point in the history
(cherry picked from commit 73a288e)
  • Loading branch information
miconda committed Aug 30, 2017
1 parent a142db9 commit e176a7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/modules/janssonrpcc/janssonrpc_connect.c
Expand Up @@ -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) {
Expand Down
25 changes: 15 additions & 10 deletions src/modules/janssonrpcc/janssonrpc_io.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e176a7e

Please sign in to comment.