janssonrpcc: couple of pkg free in case of errors
authorDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 28 Jul 2017 07:47:03 +0000 (09:47 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 28 Jul 2017 08:30:19 +0000 (10:30 +0200)
src/modules/janssonrpcc/janssonrpc_connect.c
src/modules/janssonrpcc/janssonrpc_io.c

index a65323d..83fd453 100644 (file)
@@ -111,14 +111,15 @@ typedef struct server_backoff_args {
 
 void server_backoff_cb(int fd, short event, void *arg)
 {
 
 void server_backoff_cb(int fd, short event, void *arg)
 {
+       unsigned int timeout;
+       server_backoff_args_t* a;
+
        if(!arg)
                return;
 
        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) {
 
        /* exponential backoff */
        if(timeout < 1) {
index 018f03e..4708a75 100644 (file)
@@ -231,8 +231,10 @@ no_route:
 
 end:
        if(freeme) free(freeme);
 
 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)
 }
 
 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)
 {
 
 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;
        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));
 
        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;
        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);
 
        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
 
        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(freeme) free(freeme);
                if(error) json_decref(error);
                free_req_cmd(req_cmd);
+               if(req) pkg_free(req);
                goto end;
        }
 
                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_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;
                        default:
                                ERR("bad netstring: unknown error (%d)\n", retval);
                                goto reconnect;