mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Zhipeng Lu <alexious@zju.edu.cn>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Desmond Cheong Zhi Xi <desmondcheongzx@gmail.com>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hfs: fix a memleak in hfs_find_init
Date: Mon, 29 Jan 2024 17:25:26 +0300	[thread overview]
Message-ID: <DCBF7671-E982-49F2-8687-DF030D2A99C7@dubeyko.com> (raw)
In-Reply-To: <38fd9f3.214a.18d5548ac0c.Coremail.alexious@zju.edu.cn>



> On 29 Jan 2024, at 15:54, alexious@zju.edu.cn wrote:
> 
>>> On 22 Jan 2024, at 20:27, Zhipeng Lu <alexious@zju.edu.cn> wrote:
>>> 
>>> When the switch statment goes to default and return an error, ptr should
>>> be freed since it is allocated in hfs_find_init.
>>> 
>> 
>> Do you have any memory leaks report? Could you share it in the comments?
>> Which use-case reproduces the issue? It will be easier to review the fix
>> If you can share the path of reproduction.
>> 
>> Thanks,
>> Slava.
> 
> Well, we found this potential memory leak by static analysis.
> 
> We found that all of hfs_find_init's callers won't release `ptr` when 
> hfs_find_init fails, while they will do release `ptr` when functions 
> that after hfs_find_init fails. This tactic observation suggests that
> hfs_find_init proberly should release `ptr` when it fails, i.e. in the
> default branch of switch in this patch.
> 
> Besides, we noticed another implementation of hfs_find_init in 
> fs/hfsplus/bfind.c, which is essentially identical to the one in 
> this patch (in fs/hfs/bfind.c) but calling `BUG();` in default branch
> to trigger an error-handling.
> 

I see. I believe it makes sense to add all of this explanation
into comment section. Modification looks good. Mostly, hfs_find_exit()
does freeing resources and if hfs_find_init() fails, then hfs_find_exit()
is never called. Maybe, it makes sense to set fd->tree = NULL too but
it is not critical, as far as I can see.

Could you please rework the comment section of the patch?

Thanks,
Slava.


  reply	other threads:[~2024-01-29 14:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22 17:27 Zhipeng Lu
2024-01-26 15:02 ` Viacheslav Dubeyko
2024-01-29 12:54   ` alexious
2024-01-29 14:25     ` Viacheslav Dubeyko [this message]
2024-01-29 15:17       ` alexious

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=DCBF7671-E982-49F2-8687-DF030D2A99C7@dubeyko.com \
    --to=slava@dubeyko.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexious@zju.edu.cn \
    --cc=desmondcheongzx@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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®