From 4f6dc80e2e075ed63fc08ec4ba9ea8c605671057 Mon Sep 17 00:00:00 2001 From: ekoby <7406535+ekoby@users.noreply.github.com> Date: Tue, 24 Nov 2020 20:03:22 -0500 Subject: [PATCH] avoid freeing error from api_resp (#187) * avoid freeing error from api_resp * handle empty paging response --- library/model_support.c | 1 - library/ziti_ctrl.c | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/library/model_support.c b/library/model_support.c index 6b89a1f4..4b94a838 100644 --- a/library/model_support.c +++ b/library/model_support.c @@ -528,7 +528,6 @@ static int parse_obj(void *obj, const char *json, jsmntok_t *tok, type_meta *met tokens_processed += rc; } else { - ZITI_LOG(TRACE, "skipping unmapped field[%.*s] while parsing %s", tok->end - tok->start, json + tok->start, meta->name); tok++; int end = tok->end; while (tok->type != JSMN_UNDEFINED && tok->start <= end) { diff --git a/library/ziti_ctrl.c b/library/ziti_ctrl.c index 7c351bf5..c781b27c 100644 --- a/library/ziti_ctrl.c +++ b/library/ziti_ctrl.c @@ -230,6 +230,11 @@ static void ctrl_body_cb(um_http_req_t *req, const char *b, ssize_t len) { resp->total = cr.meta.pagination.total; resp->resp_array = realloc(resp->resp_array, (resp->total + 1) * sizeof(void *)); } + // empty result + if (resp->resp_array == NULL) { + resp->resp_array = calloc(1, sizeof(void *)); + } + void **chunk = resp_obj; while (*chunk != NULL) { resp->resp_array[resp->recd++] = *chunk++; @@ -249,7 +254,8 @@ static void ctrl_body_cb(um_http_req_t *req, const char *b, ssize_t len) { } } - free_api_resp(&cr); + free_resp_meta(&cr.meta); + FREE(cr.data); FREE(resp->body); resp->ctrl_cb(resp_obj, cr.error, resp);