Skip to content

Commit

Permalink
trace: fix str_dup mem leak
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Feb 7, 2024
1 parent 8267e76 commit cc6dd7a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ int re_trace_close(void)
int re_trace_flush(void)
{
#ifdef RE_TRACE_ENABLED
int i, flush_count;
int flush_count;
struct trace_event *event_tmp;
struct trace_event *e;
char *json_arg;
Expand All @@ -255,11 +255,6 @@ int re_trace_flush(void)
if (!re_atomic_rlx(&trace.init))
return 0;

size_t json_arg_sz = 4096;
json_arg = mem_zalloc(json_arg_sz, NULL);
if (!json_arg)
return ENOMEM;

mtx_lock(&trace.lock);
event_tmp = trace.event_buffer_flush;
trace.event_buffer_flush = trace.event_buffer;
Expand All @@ -269,7 +264,18 @@ int re_trace_flush(void)
trace.event_count = 0;
mtx_unlock(&trace.lock);

for (i = 0; i < flush_count; i++)
size_t json_arg_sz = 4096;
json_arg = mem_zalloc(json_arg_sz, NULL);
if (!json_arg) {
for (int i = 0; i < flush_count; i++) {
e = &trace.event_buffer_flush[i];
if (e->arg_type == RE_TRACE_ARG_STRING_COPY)
mem_deref((void *)e->arg.a_str);
}
return ENOMEM;
}

for (int i = 0; i < flush_count; i++)
{
e = &trace.event_buffer_flush[i];

Expand Down

0 comments on commit cc6dd7a

Please sign in to comment.