Skip to content
Snippets Groups Projects
Commit ec3b77ec authored by Jan Blunck's avatar Jan Blunck Committed by Chris Wright
Browse files

[PATCH] sg.c: fix a memory leak in devices seq_file implementation (2nd)


I know that scsi procfs is legacy code but this is a fix for a memory leak.

While reading through sg.c I realized that the implementation of
/proc/scsi/sg/devices with seq_file is leaking memory due to freeing the
pointer returned by the next() iterator method. Since next() might
return NULL or an error this is wrong. This patch fixes it through using
the seq_files private field for holding the reference to the iterator
object.

Here is a small bash script to trigger the leak. Use slabtop to watch
the size-32 usage grow and grow.

#!/bin/sh

while true; do
	cat /proc/scsi/sg/devices > /dev/null
done

Signed-off-by: default avatarJan Blunck <j.blunck@tu-harburg.de>
Signed-off-by: default avatarChris Wright <chrisw@osdl.org>
parent 7b1bfbc0
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment