All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: liuye <liuye@kylinos.cn>, akpm@linux-foundation.org, shuah@kernel.org
Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/mm/cow : Fix memory leak in child_vmsplice_memcmp_fn()
Date: Tue, 14 Jan 2025 11:23:59 +0100	[thread overview]
Message-ID: <4fd2fdca-ea98-499f-ba04-0f1140180ba4@redhat.com> (raw)
In-Reply-To: <20250114022929.46364-1-liuye@kylinos.cn>

On 14.01.25 03:29, liuye wrote:
>      Release memory before exception branch returns to prevent memory leaks.
> 
> Signed-off-by: liuye <liuye@kylinos.cn>
> ---
>   tools/testing/selftests/mm/cow.c | 21 ++++++++++++++++-----
>   1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c
> index 1238e1c5aae1..959327ba6258 100644
> --- a/tools/testing/selftests/mm/cow.c
> +++ b/tools/testing/selftests/mm/cow.c
> @@ -167,19 +167,30 @@ static int child_vmsplice_memcmp_fn(char *mem, size_t size,
>   	/* Backup the original content. */
>   	memcpy(old, mem, size);
>   
> -	if (pipe(fds) < 0)
> +	if (pipe(fds) < 0) {
> +		free(old);
> +		free(new);
>   		return -errno;
> -
> +	}
>   	/* Trigger a read-only pin. */
>   	transferred = vmsplice(fds[1], &iov, 1, 0);
> -	if (transferred < 0)
> +	if (transferred < 0) {
> +		free(old);
> +		free(new);
>   		return -errno;
> -	if (transferred == 0)
> +	}
> +	if (transferred == 0) {
> +		free(old);
> +		free(new);
>   		return -EINVAL;
> +	}
>   
>   	/* Unmap it from our page tables. */
> -	if (munmap(mem, size) < 0)
> +	if (munmap(mem, size) < 0) {
> +		free(old);
> +		free(new);
>   		return -errno;
> +	}

We are immediately exiting the test in do_test_cow_in_parent()
	exit(fn(mem, size, &comm_pipes));

Your changes make the code unnecessarily more complicated to read, so 
I'm not in favor of this one to make some checker tool happy.

-- 
Cheers,

David / dhildenb


  reply	other threads:[~2025-01-14 10:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-14  2:29 [PATCH] selftests/mm/cow : Fix memory leak in child_vmsplice_memcmp_fn() liuye
2025-01-14 10:23 ` David Hildenbrand [this message]
2025-01-15  5:45   ` liuye
2025-01-20 20:16     ` 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=4fd2fdca-ea98-499f-ba04-0f1140180ba4@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liuye@kylinos.cn \
    --cc=shuah@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.