linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Kutzer, Philipp" <philipp.kutzer@siemens-healthineers.com>
Cc: "linux-trace-devel@vger.kernel.org" <linux-trace-devel@vger.kernel.org>
Subject: Re: [PATCH] libtrace: Fix memory leak in tracefs_cpu
Date: Thu, 3 Apr 2025 15:14:04 -0400	[thread overview]
Message-ID: <20250403151404.0ab1b9df@gandalf.local.home> (raw)
In-Reply-To: <AM9PR05MB77778BE58632548B4D3EEBECB5DF2@AM9PR05MB7777.eurprd05.prod.outlook.com>

On Mon, 17 Mar 2025 11:24:36 +0000
"Kutzer, Philipp" <philipp.kutzer@siemens-healthineers.com> wrote:

> From: Philipp Kutzer <philipp.kutzer@siemens-healthineers.com>
> 
> Hi,
> 
> with the introduction of the interface to allow the tracefs_cpu to handle buffer allocation on their
>  own a memory leak was built in. 
> (Commit 1e1cc549d7e7fa408081e03e4effd3591a131ae5 - libtracefs: Add API to read tracefs_cpu 
> and return a kbuffer)
> 
> We cyclically call the tracefs_iterate_raw_events function from one of our applications and 
> noticed that our application was increasingly allocating memory. 
> 
> With the help of Address Sanitizer the root cause, allocating but not freeing memory 
> for "tcpu->buffer" was found. The fix will free memory during close and cleanup function 
> and has been successfully tested in our environment. The original problem (memory leak) 
> has been resolved.

Note, I cleaned up the change log:

    libtrace: Fix memory leak in tracefs_cpu
    
    The introduction of the interface to allow the tracefs_cpu to handle buffer
    allocation on their own caused a memory leak.  (Commit 1e1cc549d7
    ("libtracefs: Add API to read tracefs_cpu and return a kbuffer")).
    
    The help of Address Sanitizer found the root cause. The "tcpu->buffer" was
    being allocated but not freed. The fix will free memory during close and
    cleanup functions.


> 
> Signed-off-by: Philipp Kutzer mailto:philipp.kutzer@siemens-healthineers.com

Also, this should be:

 Signed-off-by: Philipp Kutzer <philipp.kutzer@siemens-healthineers.com>

> ---
> 
> diff --git a/src/tracefs-record.c b/src/tracefs-record.c
> index a2dcfc2..4cd0917 100644
> --- a/src/tracefs-record.c
> +++ b/src/tracefs-record.c
> @@ -293,6 +293,8 @@ void tracefs_cpu_close(struct tracefs_cpu *tcpu)
>         if (!tcpu)
>                 return;
> 
> +       free(tcpu->buffer);
> +       tcpu->buffer = NULL;
>         close(tcpu->fd);
>         tracefs_cpu_free_fd(tcpu);
> }

This also had whitespace issues.

I fixed it up and applied it.

Thanks,

-- Steve

      reply	other threads:[~2025-04-03 19:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-17 11:24 [PATCH] libtrace: Fix memory leak in tracefs_cpu Kutzer, Philipp
2025-04-03 19:14 ` Steven Rostedt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250403151404.0ab1b9df@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=philipp.kutzer@siemens-healthineers.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).