libtracefs: Prevent a memory leak in open_cpu_files()

In open_cpu_files(), if realloc() fails, the latest allocated tcpu
isn't freed. Rearrange the loop to prevent that.

Link: https://lore.kernel.org/linux-trace-devel/20240606153830.2666120-10-jmarchan@redhat.com

Fixes: 564bffddcb117 ("libtracefs: Use tracefs_cpu_read() for tracefs_iterate_raw_events()")
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 file changed