diff --git a/src/trace/trace.c b/src/trace/trace.c index c49875d7e..397d48989 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -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; } @@ -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; @@ -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; @@ -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; } diff --git a/test/trace.c b/test/trace.c index be85c828e..6966be3e2 100644 --- a/test/trace.c +++ b/test/trace.c @@ -67,5 +67,7 @@ int test_trace(void) #endif out: + if (err) + re_trace_close(); return err; }