mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: Zhu Jun <zhujun2@cmss.chinamobile.com>,
	shuah@kernel.org, akpm@linux-foundation.org
Cc: cyphar@cyphar.com, jeffxu@google.com, sauravshah.31@gmail.com,
	gthelen@google.com, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] selftests/memfd:Fix a resource leak
Date: Wed, 10 Jul 2024 10:07:28 -0600	[thread overview]
Message-ID: <7521837f-72ba-4558-b1df-77aec2c5f5f1@linuxfoundation.org> (raw)
In-Reply-To: <20240710073351.6479-1-zhujun2@cmss.chinamobile.com>

On 7/10/24 01:33, Zhu Jun wrote:
>  From a good programming practice perspective, especially in more
> complex programs, explicitly freeing allocated memory is a good habit.
> 

The change looks good to me, however can you elaborate more on what
kind of leak your fixing here?

> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
> ---
>   tools/testing/selftests/memfd/memfd_test.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
> index 95af2d78fd31..f842a4aeb47d 100644
> --- a/tools/testing/selftests/memfd/memfd_test.c
> +++ b/tools/testing/selftests/memfd/memfd_test.c
> @@ -661,9 +661,11 @@ static void mfd_assert_grow_write(int fd)
>   	l = pwrite(fd, buf, mfd_def_size * 8, 0);
>   	if (l != (mfd_def_size * 8)) {
>   		printf("pwrite() failed: %m\n");
> +		free(buf);
>   		abort();
>   	}
>   
> +	free(buf);
>   	mfd_assert_size(fd, mfd_def_size * 8);
>   }
>   
> @@ -685,8 +687,11 @@ static void mfd_fail_grow_write(int fd)
>   	l = pwrite(fd, buf, mfd_def_size * 8, 0);
>   	if (l == (mfd_def_size * 8)) {
>   		printf("pwrite() didn't fail as expected\n");
> +		free(buf);
>   		abort();
>   	}
> +
> +	free(buf);
>   }
>   
>   static void mfd_assert_mode(int fd, int mode)
> @@ -771,9 +776,11 @@ static pid_t spawn_thread(unsigned int flags, int (*fn)(void *), void *arg)
>   	pid = clone(fn, stack + STACK_SIZE, SIGCHLD | flags, arg);
>   	if (pid < 0) {
>   		printf("clone() failed: %m\n");
> +		free(stack);
>   		abort();
>   	}
>   
> +	free(stack);
>   	return pid;
>   }
>   

thanks,
-- Shuah

      reply	other threads:[~2024-07-10 16:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-10  7:33 Zhu Jun
2024-07-10 16:07 ` Shuah Khan [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=7521837f-72ba-4558-b1df-77aec2c5f5f1@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=cyphar@cyphar.com \
    --cc=gthelen@google.com \
    --cc=jeffxu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=sauravshah.31@gmail.com \
    --cc=shuah@kernel.org \
    --cc=zhujun2@cmss.chinamobile.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®