diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-03-12 12:56:54 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-03-12 12:56:54 +0200 |
commit | 22416a1df87f93f611af1ef419f921ed358a8115 (patch) | |
tree | fce60600b9dc28a436cbbbb770b363b073c3004a | |
parent | 375483f873c30756f7a37322237eb92a957e04e2 (diff) | |
download | ping903-22416a1df87f93f611af1ef419f921ed358a8115.tar.gz ping903-22416a1df87f93f611af1ef419f921ed358a8115.tar.bz2 |
Fix double-free error
* src/ping903.c (http_response_detail): Don't free errobj
after passing it to httpd_json_response.
-rw-r--r-- | src/ping903.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/ping903.c b/src/ping903.c index 06597bb..df1196b 100644 --- a/src/ping903.c +++ b/src/ping903.c @@ -293,25 +293,21 @@ http_response_detail(struct MHD_Connection *conn, char const *method, char const *url, int status, char const *message, int index) { - struct json_value *jv, *errobj = json_new_object(); - int rc; + struct json_value *jv = NULL, *errobj = json_new_object(); if (!errobj) goto err; - if ((jv = json_new_string(message)) == NULL) - goto err; - if (json_object_set(errobj, "message", jv)) + if ((jv = json_new_string(message)) == NULL + || json_object_set(errobj, "message", jv)) goto err; if (index) { - if ((jv = json_new_number(index)) == NULL) - goto err; - if (json_object_set(errobj, "index", jv)) + if ((jv = json_new_number(index)) == NULL + || json_object_set(errobj, "index", jv)) goto err; } - rc = httpd_json_response(conn, url, method, status, errobj); - json_value_free(errobj); - return rc; + return httpd_json_response(conn, url, method, status, errobj); err: + json_value_free(jv); json_value_free(errobj); return http_response(conn, method, url, MHD_HTTP_INTERNAL_SERVER_ERROR); |