Skip to contentSkip to conversation

ss: fix directory leak when -T option is used

PATCH Applied Maxim Petrov 2 participants 2 messages Oct 21, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ss: fix directory leak when -T option is used

To get information about threads used in a process, the /proc/$PID/task directory content is analyzed by ss code. However, the opened 'dirent' object is not closed after use, leading to memory leaks. Add missing closedir call in 'user_ent_hash_build' to avoid it.

Detected by valgrind: "valgrind ./misc/ss -T"

Fixes e2267e68b9b5 ("ss: Introduce -T, --threads option")
---
 misc/ss.c | 1 +
 1 file changed, 1 insertion(+)
misc/ss.c +1 -0
index 7e67dbe4..2628c2e0 100644
@@ -678,6 +678,7 @@ static void user_ent_hash_build(void)
 				snprintf(name + nameoff, sizeof(name) - nameoff, "%d/", tid);
 				user_ent_hash_build_task(name, pid, tid);
 			}
+			closedir(task_dir);
 		}
 	}
 	closedir(dir);
Signature · 1 line
2.30.2
#1 lore raw
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 8 lines · On Sat, 21 Oct 2023 10:44:08 +0200 you wrote:

To get information about threads used in a process, the /proc/$PID/task directory content is analyzed by ss code. However, the opened 'dirent' object is not closed after use, leading to memory leaks. Add missing closedir call in 'user_ent_hash_build' to avoid it.

Detected by valgrind: "valgrind ./misc/ss -T"

[...]

Here is the summary with links:
- [iproute2] ss: fix directory leak when -T option is used

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=d233ff0f984a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html