From: David Hildenbrand <david@redhat.com>
To: Feng Jiang <jiangfeng@kylinos.cn>,
akpm@linux-foundation.org, shuah@kernel.org
Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, Ming Xie <xieming@kylinos.cn>
Subject: Re: [PATCH] selftests/mm: fix memory leak in child_memcmp_fn
Date: Tue, 4 Apr 2023 09:31:14 +0200 [thread overview]
Message-ID: <5c415fa5-1637-883d-8136-fc4280274406@redhat.com> (raw)
In-Reply-To: <20230404031234.78272-1-jiangfeng@kylinos.cn>
On 04.04.23 05:12, Feng Jiang wrote:
> The allocated memory should be freed on return.
>
> Signed-off-by: Feng Jiang <jiangfeng@kylinos.cn>
> Suggested-by: Ming Xie <xieming@kylinos.cn>
> ---
> tools/testing/selftests/mm/cow.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c
> index 0eb2e8180aa5..c0dd2dfca51b 100644
> --- a/tools/testing/selftests/mm/cow.c
> +++ b/tools/testing/selftests/mm/cow.c
> @@ -162,6 +162,10 @@ static int child_memcmp_fn(char *mem, size_t size,
> {
> char *old = malloc(size);
> char buf;
> + int ret;
> +
> + if (!old)
> + return -ENOMEM;
>
> /* Backup the original content. */
> memcpy(old, mem, size);
> @@ -172,7 +176,10 @@ static int child_memcmp_fn(char *mem, size_t size,
> ;
>
> /* See if we still read the old values. */
> - return memcmp(old, mem, size);
> + ret = memcmp(old, mem, size);
> + free(old);
> +
> + return ret;
> }
>
> static int child_vmsplice_memcmp_fn(char *mem, size_t size,
NAK, the whole point of this function is that the child process will
exit immediately after executing this function, cleaning up automatically.
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2023-04-04 7:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-04 3:12 Feng Jiang
2023-04-04 7:31 ` David Hildenbrand [this message]
2023-04-06 2:01 ` Feng Jiang
2023-04-06 10:37 ` 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=5c415fa5-1637-883d-8136-fc4280274406@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=jiangfeng@kylinos.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shuah@kernel.org \
--cc=xieming@kylinos.cn \
/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