Skip to content

Commit

Permalink
trace: fix oom test
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Feb 8, 2024
1 parent cc6dd7a commit 9c9ef54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ int re_trace_init(const char *json_file)
trace.event_buffer_flush = mem_zalloc(
TRACE_BUFFER_SIZE * sizeof(struct trace_event), NULL);
if (!trace.event_buffer_flush) {
mem_deref(trace.event_buffer);
trace.event_buffer = mem_deref(trace.event_buffer);
return ENOMEM;
}

Expand All @@ -191,8 +191,8 @@ int re_trace_init(const char *json_file)
out:
if (err) {
re_atomic_rlx_set(&trace.init, false);
mem_deref(trace.event_buffer);
mem_deref(trace.event_buffer_flush);
trace.event_buffer = mem_deref(trace.event_buffer);
trace.event_buffer_flush = mem_deref(trace.event_buffer_flush);
}

return err;
Expand Down Expand Up @@ -249,8 +249,8 @@ int re_trace_flush(void)
struct trace_event *event_tmp;
struct trace_event *e;
char *json_arg;
char name[128] = {0};
char id_str[128] = {0};
char name[128] = {0};
char id_str[128] = {0};

if (!re_atomic_rlx(&trace.init))
return 0;
Expand All @@ -271,6 +271,9 @@ int re_trace_flush(void)
e = &trace.event_buffer_flush[i];
if (e->arg_type == RE_TRACE_ARG_STRING_COPY)
mem_deref((void *)e->arg.a_str);

if (e->id)
mem_deref(e->id);
}
return ENOMEM;
}
Expand Down
2 changes: 2 additions & 0 deletions test/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ int test_trace(void)
#endif

out:
if (err)
re_trace_close();
return err;
}

0 comments on commit 9c9ef54

Please sign in to comment.