Bug 217127 - Fix memory leak in tracecmd_compress_copy_from()
Summary: Fix memory leak in tracecmd_compress_copy_from()
Status: RESOLVED CODE_FIX
Alias: None
Product: Tools
Classification: Unclassified
Component: Trace-cmd/Kernelshark (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Default virtual assignee for Trace-cmd and kernelshark
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-04 09:20 UTC by Markus Elfring
Modified: 2023-06-07 19:41 UTC (History)
1 user (show)

See Also:
Kernel Version: 6.2.2
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Markus Elfring 2023-03-04 09:20:06 UTC
The information “Memory leak: buf_from” was provided by the source code analysis tool “Cppcheck 2.10”.
https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/tree/lib/trace-cmd/trace-compress.c?id=0a68daed9f58e4429c0f1e7818f7cc0634873112#n699

Memory which is referenced by the variable “buf_from” is not released so far if another memory allocation for the variable “buf_to” failed within the implementation of the function “tracecmd_compress_copy_from”.
Comment 1 Markus Elfring 2023-03-04 10:52:49 UTC
Further data processing is performed after an allocation of a buffer instance succeeded.
The variable “instance” contains a valid pointer then.
But this pointer was checked again after the creation of a tracefs instance failed within the implementation of the function “allocate_instance”.
https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/tree/tracecmd/trace-record.c?id=0a68daed9f58e4429c0f1e7818f7cc0634873112#n360

* I suggest to remove the redundant check.
* May it be avoided to pass a null pointer to a call of the function “tracefs_instance_free”?
Comment 2 Steven Rostedt 2023-06-07 19:41:07 UTC
Fixed by https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/commit/?id=d7ce897734a9046b28866a13d12e78e9d492c72a

("libtracecmd: Free buf_from in error path of tracecmd_compress_copy_from()")

Note You need to log in before you can comment on or make changes to this bug.