Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cfl_record_accessor: Plug resource leaks (CID 516097) #9728

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions src/flb_cfl_record_accessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,72 +532,72 @@ static int cfl_to_json(struct cfl_variant *var, flb_sds_t buf)

switch (var->type) {
case CFL_VARIANT_NULL:
flb_sds_cat(buf, "null", 4);
flb_sds_cat_safe(&buf, "null", 4);
break;
case CFL_VARIANT_BOOL:
if (var->data.as_bool) {
flb_sds_cat(buf, "true", 4);
flb_sds_cat_safe(&buf, "true", 4);
}
else {
flb_sds_cat(buf, "false", 5);
flb_sds_cat_safe(&buf, "false", 5);
}
break;
case CFL_VARIANT_INT: {
char tmp[32] = {0};
i = snprintf(tmp, sizeof(tmp)-1, "%"PRId64, var->data.as_int64);
flb_sds_cat(buf, tmp, i);
flb_sds_cat_safe(&buf, tmp, i);
break;
}
case CFL_VARIANT_UINT: {
char tmp[32] = {0};
i = snprintf(tmp, sizeof(tmp)-1, "%"PRIu64, var->data.as_uint64);
flb_sds_cat(buf, tmp, i);
flb_sds_cat_safe(&buf, tmp, i);
break;
}
case CFL_VARIANT_DOUBLE: {
char tmp[512] = {0};
i = snprintf(tmp, sizeof(tmp)-1, "%"PRIu64, var->data.as_uint64);
flb_sds_cat(buf, tmp, i);
flb_sds_cat_safe(&buf, tmp, i);
break;
}
case CFL_VARIANT_STRING:
flb_sds_cat(buf, "\"", 1);
flb_sds_cat(buf, var->data.as_string, cfl_sds_len(var->data.as_string));
flb_sds_cat(buf, "\"", 1);
flb_sds_cat_safe(&buf, "\"", 1);
flb_sds_cat_safe(&buf, var->data.as_string, cfl_sds_len(var->data.as_string));
flb_sds_cat_safe(&buf, "\"", 1);
break;
case CFL_VARIANT_BYTES:
flb_sds_cat(buf, "\"", 1);
flb_sds_cat(buf, var->data.as_string, cfl_sds_len(var->data.as_bytes));
flb_sds_cat(buf, "\"", 1);
flb_sds_cat_safe(&buf, "\"", 1);
flb_sds_cat_safe(&buf, var->data.as_string, cfl_sds_len(var->data.as_bytes));
flb_sds_cat_safe(&buf, "\"", 1);
break;
case CFL_VARIANT_ARRAY: {
struct cfl_array *array = var->data.as_array;
loop = cfl_array_size(array);

flb_sds_cat(buf, "[", 1);
flb_sds_cat_safe(&buf, "[", 1);
if (loop != 0) {
for (i = 0; i < loop - 1; i++) {
cfl_to_json(array->entries[i], buf);
flb_sds_cat(buf, ",", 1);
flb_sds_cat_safe(&buf, ",", 1);
}
}
cfl_to_json(array->entries[loop-1], buf);
flb_sds_cat(buf, "]", 1);
flb_sds_cat_safe(&buf, "]", 1);
break;
}
case CFL_VARIANT_KVLIST:
kvlist = var->data.as_kvlist;
flb_sds_cat(buf, "{", 1);
flb_sds_cat_safe(&buf, "{", 1);
cfl_list_foreach(head, &kvlist->list) {
kv = cfl_list_entry(head, struct cfl_kvpair, _head);

/* key */
flb_sds_cat(buf, "\"", 1);
flb_sds_cat(buf, kv->key, cfl_sds_len(kv->key));
flb_sds_cat(buf, "\"", 1);
flb_sds_cat_safe(&buf, "\"", 1);
flb_sds_cat_safe(&buf, kv->key, cfl_sds_len(kv->key));
flb_sds_cat_safe(&buf, "\"", 1);

/* separator */
flb_sds_cat(buf, ":", 1);
flb_sds_cat_safe(&buf, ":", 1);

/* value */
ret = cfl_to_json(kv->val, buf);
Expand All @@ -606,7 +606,7 @@ static int cfl_to_json(struct cfl_variant *var, flb_sds_t buf)
}
break;
}
flb_sds_cat(buf, "}", 1);
flb_sds_cat_safe(&buf, "}", 1);
}

return 0;
Expand Down
Loading