diff mbox series

common/rc: cleanup old .kmemleak files

Message ID 20230712145101.4286-1-lhenriques@suse.de (mailing list archive)
State New, archived
Headers show
Series common/rc: cleanup old .kmemleak files | expand

Commit Message

Luis Henriques July 12, 2023, 2:51 p.m. UTC
I've spent a non-negligible amount of time looking into a kmemleak that
didn't exist in the code I was testing because there was an old .kmemleak
file in the results directory.  I don't think this is an intended behaviour,
so I'm proposing to remove these files everytime we capture the result of a
new scan.

Signed-off-by: Luís Henriques <lhenriques@suse.de>
---
 common/rc | 2 ++
 1 file changed, 2 insertions(+)

Comments

Darrick J. Wong July 12, 2023, 4:32 p.m. UTC | #1
On Wed, Jul 12, 2023 at 03:51:01PM +0100, Luís Henriques wrote:
> I've spent a non-negligible amount of time looking into a kmemleak that
> didn't exist in the code I was testing because there was an old .kmemleak
> file in the results directory.  I don't think this is an intended behaviour,
> so I'm proposing to remove these files everytime we capture the result of a
> new scan.
> 
> Signed-off-by: Luís Henriques <lhenriques@suse.de>
> ---
>  common/rc | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/common/rc b/common/rc
> index 741579af82d2..6aa6be704e51 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -4433,6 +4433,8 @@ _capture_kmemleak()
>  	local kern_knob="$DEBUGFS_MNT/kmemleak"
>  	local leak_file="$1"
>  
> +	rm -f "$leak_file"

Some callers of this helper specify a device file when all they want to
do is clear the old kmemleak report data:

$ git grep -w _capture_kmemleak
common/rc:4490:_capture_kmemleak()
common/rc:4535:         _capture_kmemleak /dev/null
common/rc:4555:         _capture_kmemleak /dev/null
common/rc:4560: _capture_kmemleak "$leak_file"

The simplest fix here I think would be:

	# Some callers pass in /dev/null when they want to clear the
	# kernel's leak report file and do not care what was in that.
	test -f "$leak_file" && rm -f "$leak_file"

--D

> +
>  	# Tell the kernel to scan for memory leaks.  Apparently the write
>  	# returns before the scan is complete, so do it twice in the hopes
>  	# that twice is enough to capture all the leaks.
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 741579af82d2..6aa6be704e51 100644
--- a/common/rc
+++ b/common/rc
@@ -4433,6 +4433,8 @@  _capture_kmemleak()
 	local kern_knob="$DEBUGFS_MNT/kmemleak"
 	local leak_file="$1"
 
+	rm -f "$leak_file"
+
 	# Tell the kernel to scan for memory leaks.  Apparently the write
 	# returns before the scan is complete, so do it twice in the hopes
 	# that twice is enough to capture all the leaks.