From 65d9136dd592ef90673241d72721ca9531242fa2 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 30 Nov 2013 18:33:09 +1100 Subject: [PATCH] Fix json parsing in api.c --- api.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/api.c b/api.c index 9459f6c9..9c0cdc9f 100644 --- a/api.c +++ b/api.c @@ -3673,7 +3673,7 @@ void api(int api_thr_id) bool addrok; char group; json_error_t json_err; - json_t *json_config; + json_t *json_config = NULL; json_t *json_val; bool isjson; bool did; @@ -3848,21 +3848,18 @@ void api(int api_thr_id) message(io_data, MSG_INVJSON, 0, NULL, isjson); send_result(io_data, c, isjson); did = true; - } - else { + } else { json_val = json_object_get(json_config, JSON_COMMAND); if (json_val == NULL) { message(io_data, MSG_MISCMD, 0, NULL, isjson); send_result(io_data, c, isjson); did = true; - } - else { + } else { if (!json_is_string(json_val)) { message(io_data, MSG_INVCMD, 0, NULL, isjson); send_result(io_data, c, isjson); did = true; - } - else { + } else { cmd = (char *)json_string_value(json_val); json_val = json_object_get(json_config, JSON_PARAMETER); if (json_is_string(json_val)) @@ -3876,11 +3873,10 @@ void api(int api_thr_id) } } } - json_decref(json_config); } } - if (!did) + if (!did) { for (i = 0; cmds[i].name != NULL; i++) { if (strcmp(cmd, cmds[i].name) == 0) { sprintf(cmdbuf, "|%s|", cmd); @@ -3896,11 +3892,14 @@ void api(int api_thr_id) break; } } + } if (!did) { message(io_data, MSG_INVCMD, 0, NULL, isjson); send_result(io_data, c, isjson); } + if (json_is_object(json_config)) + json_decref(json_config); } } CLOSESOCKET(c);