]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ss: fix directory leak when -T option is used
authorMaxim Petrov <mmrmaximuzz@gmail.com>
Sat, 21 Oct 2023 08:44:08 +0000 (10:44 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Sat, 21 Oct 2023 16:41:55 +0000 (09:41 -0700)
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")
Signed-off-by: Maxim Petrov <mmrmaximuzz@gmail.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
misc/ss.c

index 7e67dbe4abb95cf7f2ad54d29ba77436100181b2..2628c2e042f1cdb616ec8aa80d4f413b41dfd3f4 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -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);