Skip to content

Commit 6effd3d

Browse files
TeroJaaskoArto Kinnunen
authored andcommitted
tr_array: fix use after free error after mbed_trace_free() is called
If one called mbed_trace_free() but continued using the trace (which is a supported use case), the already freed tmp_data buffer was used by tr_array(). This was spotted by Valgrind on some unit tests which do enable the trace only temporarily for some of the tests. Error being fixed in this PR: --8<--8<--8<--- ==5865== Invalid write of size 1 ==5865== at 0x2639BB: mbed_trace_array (mbed_trace.c:569) <...> ==5865== Address 0x5dc79d0 is 0 bytes inside a block of size 128 free'd ==5865== at 0x4C32D3B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5865== by 0x262723: mbed_trace_free (mbed_trace.c:192) <...> ==5865== Block was alloc'd at ==5865== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5865== by 0x262548: mbed_trace_init (mbed_trace.c:162) <...>
1 parent 6c50a18 commit 6effd3d

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

platform/mbed-trace/source/mbed_trace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ void mbed_trace_free(void)
209209
m_trace.line_length = DEFAULT_TRACE_LINE_LENGTH;
210210
m_trace.tmp_data = 0;
211211
m_trace.tmp_data_length = DEFAULT_TRACE_TMP_LINE_LEN;
212+
m_trace.tmp_data_ptr = 0;
212213
m_trace.prefix_f = 0;
213214
m_trace.suffix_f = 0;
214215
m_trace.printf = mbed_trace_default_print;

0 commit comments

Comments
 (0)