mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Haofeng Li <920484857@qq.com>
To: david@redhat.com, Andrew Morton <akpm@linux-foundation.org>
Cc: 13266079573@163.com, 920484857@qq.com, lihaofeng@kylinos.cn,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-mm@kvack.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com
Subject: Re: [PATCH] mm: transhuge-stress: fix potential memory leak on realloc failure
Date: Fri, 12 Sep 2025 18:10:05 +0800	[thread overview]
Message-ID: <tencent_43768D3DB24034B62C249781C1DE7359C807@qq.com> (raw)
In-Reply-To: <b6f38984-5f89-4a9d-a905-ddcdbd7510a3@redhat.com>

From: David Hildenbrand <david@redhat.com>
>What do you think happens when a process exits? :)

>Correct! All memory ever allocated to that process gets freed, avoiding 
>any memory leaks.

Thanks for pointing this out. You are absolutely correct that the operating system will reclaim all allocated memory when a process exits, so there is no persistent memory leak in this specific scenario.

I opted to add explicit memory freeing in the error path primarily as a practice for better long-term maintainability:

It ensures correctness if the code structure changes in the future (e.g., becomes part of a longer-running routine).

It maintains consistency with other error paths in the codebase.

It prevents false positives from static analysis tools (like valgrind).

I'm happy to adjust it if you still think it's preferable to remove the free() in this context.

Best regards,
	Haofeng Li


  reply	other threads:[~2025-09-12 10:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-12  8:20 Haofeng Li
2025-09-12  9:28 ` David Hildenbrand
2025-09-12 10:10   ` Haofeng Li [this message]
2025-09-12 11:36     ` David Hildenbrand

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=tencent_43768D3DB24034B62C249781C1DE7359C807@qq.com \
    --to=920484857@qq.com \
    --cc=13266079573@163.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=lihaofeng@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=ziy@nvidia.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

all inboxes | Powered by JetHome®