Skip to content

Commit

Permalink
decode_statsd: fixed resource leaks
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Alminana <[email protected]>
  • Loading branch information
leonardo-albertovich committed Aug 29, 2024
1 parent 9711d3e commit 792836d
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/cmt_decode_statsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@ static int decode_labels(struct cmt *cmt,
}
label_k = cfl_sds_create_len(label_kv, colon - label_kv);
if (label_k == NULL) {
for (label_index = 0 ; label_index < 128 ; label_index++) {
if (value_index_list[label_index] != NULL) {
cfl_sds_destroy(value_index_list[label_index]);
}
}

free(value_index_list);

if (kvs != NULL) {
cfl_utils_split_free(kvs);
}
Expand All @@ -167,7 +174,15 @@ static int decode_labels(struct cmt *cmt,
label_v = cfl_sds_create_len(colon + 1, strlen(label_kv) - strlen(label_k) - 1);
if (label_v == NULL) {
cfl_sds_destroy(label_k);

for (label_index = 0 ; label_index < 128 ; label_index++) {
if (value_index_list[label_index] != NULL) {
cfl_sds_destroy(value_index_list[label_index]);
}
}

free(value_index_list);

if (kvs != NULL) {
cfl_utils_split_free(kvs);
}
Expand All @@ -190,7 +205,15 @@ static int decode_labels(struct cmt *cmt,
if (label_index > 127) {
cfl_sds_destroy(label_k);
cfl_sds_destroy(label_v);

for (label_index = 0 ; label_index < 128 ; label_index++) {
if (value_index_list[label_index] != NULL) {
cfl_sds_destroy(value_index_list[label_index]);
}
}

free(value_index_list);

if (kvs != NULL) {
cfl_utils_split_free(kvs);
}
Expand Down Expand Up @@ -227,20 +250,18 @@ static int decode_labels(struct cmt *cmt,
}
}

for (map_label_index = 0 ;
result == CMT_DECODE_STATSD_SUCCESS &&
map_label_index < map_label_count ;
map_label_index++) {
label_v = (cfl_sds_t) value_index_list[map_label_index];
cfl_sds_destroy(label_v);
for (label_index = 0 ; label_index < 128 ; label_index++) {
if (value_index_list[label_index] != NULL) {
cfl_sds_destroy(value_index_list[label_index]);
}
}

free(value_index_list);

if (kvs != NULL) {
cfl_utils_split_free(kvs);
}

free(value_index_list);

return result;
}

Expand Down

0 comments on commit 792836d

Please sign in to comment.