linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Haofeng Li <920484857@qq.com>, Andrew Morton <akpm@linux-foundation.org>
Cc: 13266079573@163.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 13:36:03 +0200	[thread overview]
Message-ID: <3f739d3e-f6fc-4a3f-9bbb-151a6dc6c083@redhat.com> (raw)
In-Reply-To: <tencent_43768D3DB24034B62C249781C1DE7359C807@qq.com>

On 12.09.25 12:10, Haofeng Li wrote:
> 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.

No code changes are required. This patch adds more complexity without 
any benefit.

-- 
Cheers

David / dhildenb



      reply	other threads:[~2025-09-12 11:36 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
2025-09-12 11:36     ` David Hildenbrand [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=3f739d3e-f6fc-4a3f-9bbb-151a6dc6c083@redhat.com \
    --to=david@redhat.com \
    --cc=13266079573@163.com \
    --cc=920484857@qq.com \
    --cc=akpm@linux-foundation.org \
    --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