From 89f05ed5a963acfe3da074d734527bac3bb23ac5 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Mon, 29 May 2017 09:59:20 +0200 Subject: [PATCH] imv-swid: Fixed memory leak in http REST interface --- src/libimcv/plugins/imv_swid/imv_swid_rest.c | 36 +++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/libimcv/plugins/imv_swid/imv_swid_rest.c b/src/libimcv/plugins/imv_swid/imv_swid_rest.c index 143b0b239..0fe96edef 100644 --- a/src/libimcv/plugins/imv_swid/imv_swid_rest.c +++ b/src/libimcv/plugins/imv_swid/imv_swid_rest.c @@ -70,27 +70,29 @@ METHOD(imv_swid_rest_t, post, status_t, FETCH_END); free(uri); - if (status == SUCCESS) + if (status != SUCCESS) { - return SUCCESS; - } - - if (code != HTTP_STATUS_CODE_PRECONDITION_FAILED || !response.ptr) - { - DBG2(DBG_IMV, "REST http request failed with status code: %d", code); - return FAILED; - } - - if (jresponse) - { - /* Parse HTTP response into a JSON object */ - tokener = json_tokener_new(); - *jresponse = json_tokener_parse_ex(tokener, response.ptr, response.len); - json_tokener_free(tokener); + if (code != HTTP_STATUS_CODE_PRECONDITION_FAILED || !response.ptr) + { + DBG2(DBG_IMV, "REST http request failed with status code: %d", code); + status = FAILED; + } + else + { + if (jresponse) + { + /* Parse HTTP response into a JSON object */ + tokener = json_tokener_new(); + *jresponse = json_tokener_parse_ex(tokener, response.ptr, + response.len); + json_tokener_free(tokener); + } + status = NEED_MORE; + } } free(response.ptr); - return NEED_MORE; + return status; } METHOD(imv_swid_rest_t, destroy, void,