server: rest_api: Fix memory leak in slotmap post

We need to decrement the refcount on the json_req object.

Change-Id: I1a550eff76e6a72013ab47ef8f240a72d7a7d9cb
This commit is contained in:
Harald Welte 2019-07-21 20:00:33 +02:00
parent 0c50c34f18
commit 3591382ffa
1 changed files with 3 additions and 1 deletions

View File

@ -309,7 +309,7 @@ static int api_cb_slotmaps_post(const struct _u_request *req, struct _u_response
struct slot_mapping slotmap, *map;
struct rspro_client_conn *conn;
json_error_t json_err;
json_t *json_req;
json_t *json_req = NULL;
int rc;
json_req = ulfius_get_json_body_request(req, &json_err);
@ -341,10 +341,12 @@ static int api_cb_slotmaps_post(const struct _u_request *req, struct _u_response
pthread_rwlock_unlock(&srv->rwlock);
json_decref(json_req);
ulfius_set_empty_body_response(resp, 201);
return U_CALLBACK_COMPLETE;
err:
json_decref(json_req);
ulfius_set_empty_body_response(resp, 400);
return U_CALLBACK_COMPLETE;
}