mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests/net: missing close function in randomize function
@ 2024-07-05  8:24 Liu Jing
  2024-07-09 10:46 ` Paolo Abeni
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Jing @ 2024-07-05  8:24 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, shuah
  Cc: netdev, linux-kselftest, linux-kernel, liujing

in randomize function, there is a open function, but there is no
close function in the randomize, which is easy to cause memory leaks.

Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
---
 tools/testing/selftests/net/tcp_mmap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/net/tcp_mmap.c b/tools/testing/selftests/net/tcp_mmap.c
index 4fcce5150850..ab305e262d0a 100644
--- a/tools/testing/selftests/net/tcp_mmap.c
+++ b/tools/testing/selftests/net/tcp_mmap.c
@@ -438,6 +438,7 @@ static void randomize(void *target, size_t count)
 		perror("read /dev/urandom");
 		exit(1);
 	}
+	close(urandom);
 }
 
 int main(int argc, char *argv[])
-- 
2.33.0




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests/net: missing close function in randomize function
  2024-07-05  8:24 [PATCH] selftests/net: missing close function in randomize function Liu Jing
@ 2024-07-09 10:46 ` Paolo Abeni
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Abeni @ 2024-07-09 10:46 UTC (permalink / raw)
  To: Liu Jing, davem, edumazet, kuba, shuah
  Cc: netdev, linux-kselftest, linux-kernel

On Fri, 2024-07-05 at 16:24 +0800, Liu Jing wrote:
> in randomize function, there is a open function, but there is no
> close function in the randomize, which is easy to cause memory leaks.

Please not that the file descriptor is not leaked, the kernel will
dispose it at process exit() time.

> 
> Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
> ---
>  tools/testing/selftests/net/tcp_mmap.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/testing/selftests/net/tcp_mmap.c b/tools/testing/selftests/net/tcp_mmap.c
> index 4fcce5150850..ab305e262d0a 100644
> --- a/tools/testing/selftests/net/tcp_mmap.c
> +++ b/tools/testing/selftests/net/tcp_mmap.c
> @@ -438,6 +438,7 @@ static void randomize(void *target, size_t count)
>  		perror("read /dev/urandom");
>  		exit(1);
>  	}
> +	close(urandom);
>  }
>  
>  int main(int argc, char *argv[])

This is outside any loop, so the overall effect WRT the self-test
itself is not visible.

I think we are better off without this kind of changes, unless they are
part of a largish re-factor.

Thanks,

Paolo


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-09 10:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-05  8:24 [PATCH] selftests/net: missing close function in randomize function Liu Jing
2024-07-09 10:46 ` Paolo Abeni

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®