Re: [PATCH] selftests/memfd: fix a memleak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2023-11-21 18:43, Andrew Morton wrote:
On Mon, 20 Nov 2023 18:55:06 -0800 zhujun2 <zhujun2@xxxxxxxxxxxxxxxxxxxx> wrote:

The memory allocated within a function should be released
before the function return,otherwise memleak will occur.

...

--- a/tools/testing/selftests/memfd/fuse_test.c
+++ b/tools/testing/selftests/memfd/fuse_test.c
@@ -217,6 +217,7 @@ static pid_t spawn_sealing_thread(void)
  		abort();
  	}
+ free(stack);
  	return pid;
  }

We just freed a thread's stack while it is still running?

Indeed, this patch is completely wrong. Freeing the stack memory should
not happen before joining the thread which uses it.

This also means that this patch was probably not even runtime-tested, even less tested with tools like valgrind which should have caught this.

I would advise the patch author to test the changes before submitting a patch, especially considering the amount of tools out there which can be used to validate userspace programs.

Moreover, the changes done should take into consideration the behavior of the system calls they surround. Trying to "fix" a resource leak without understanding first the semantic of the system call using the resource is causing more problems than it solves.

Thanks,

Mathieu


--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux