Skip to content

Commit

Permalink
avoid freeing error from api_resp (#187)
Browse files Browse the repository at this point in the history
* avoid freeing error from api_resp

* handle empty paging response
  • Loading branch information
ekoby authored Nov 25, 2020
1 parent 618911a commit 4f6dc80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 0 additions & 1 deletion library/model_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion library/ziti_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -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);
Expand Down

0 comments on commit 4f6dc80

Please sign in to comment.