From 8ce39f592ca537945bd1576e651b7fad4307d612 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Wed, 26 Nov 2014 17:22:55 +0100 Subject: [PATCH] procname_kill(): Fix possible resource leak and let's use opendir() errno Signed-off-by: Joachim Nilsson --- helpers.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/helpers.c b/helpers.c index 1f0d3bb4..fca5cdef 100644 --- a/helpers.c +++ b/helpers.c @@ -270,12 +270,15 @@ int procname_kill(char *name, int signo) DIR *dir; struct dirent *entry; - dir = opendir("/proc"); - if (!dir || !name) { + if (!name) { errno = EINVAL; return 0; } + dir = opendir("/proc"); + if (!dir) + return 0; + while ((entry = readdir(dir)) != NULL) { /* Skip non-process entries in /proc */ if (!isdigit(*entry->d_name))