Module: kamailio
Branch: master
Commit: ec0ba37b9f2b6c60303227ea0527d69896f2930e
URL:
https://github.com/kamailio/kamailio/commit/ec0ba37b9f2b6c60303227ea0527d69…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-08-27T15:58:48+02:00
jsonrpc-c: proper error handling for pipe cmd callback
- credits to Hugh Waite for spotting missing return
- free vars if already set when error handling is done
---
Modified: modules/jsonrpc-c/jsonrpc_io.c
---
Diff:
https://github.com/kamailio/kamailio/commit/ec0ba37b9f2b6c60303227ea0527d69…
Patch:
https://github.com/kamailio/kamailio/commit/ec0ba37b9f2b6c60303227ea0527d69…
---
diff --git a/modules/jsonrpc-c/jsonrpc_io.c b/modules/jsonrpc-c/jsonrpc_io.c
index 42d16be..aac3eab 100644
--- a/modules/jsonrpc-c/jsonrpc_io.c
+++ b/modules/jsonrpc-c/jsonrpc_io.c
@@ -144,6 +144,11 @@ int (*res_cb)(json_object*, char*, int) = &result_cb;
void cmd_pipe_cb(int fd, short event, void *arg)
{
struct jsonrpc_pipe_cmd *cmd;
+ char *ns = 0;
+ size_t bytes;
+ json_object *payload = NULL;
+ jsonrpc_request_t *req = NULL;
+ json_object *params;
/* struct event *ev = (struct event*)arg; */
if (read(fd, &cmd, sizeof(cmd)) != sizeof(cmd)) {
@@ -151,9 +156,7 @@ void cmd_pipe_cb(int fd, short event, void *arg)
return;
}
- json_object *params = json_tokener_parse(cmd->params);
- json_object *payload = NULL;
- jsonrpc_request_t *req = NULL;
+ params = json_tokener_parse(cmd->params);
if (cmd->notify_only) {
payload = build_jsonrpc_notification(cmd->method, params);
@@ -169,7 +172,6 @@ void cmd_pipe_cb(int fd, short event, void *arg)
}
char *json = (char*)json_object_get_string(payload);
- char *ns; size_t bytes;
bytes = netstring_encode_new(&ns, json, (size_t)strlen(json));
struct jsonrpc_server_group *g;
@@ -240,7 +242,11 @@ void cmd_pipe_cb(int fd, short event, void *arg)
pkg_free(ns);
json_object_put(payload);
if (cmd->notify_only) free_pipe_cmd(cmd);
+ return;
+
error:
+ if(ns) pkg_free(ns);
+ if(payload) json_object_put(payload);
if (cmd->notify_only) free_pipe_cmd(cmd);
return;
}