From 21386a358f0850b660139fe6db2bdd2e14c8a4ef Mon Sep 17 00:00:00 2001 From: Jan Zeleny Date: Fri, 4 Nov 2011 04:08:36 -0400 Subject: Fixed possible resource leak in get_uid_from_pid() https://fedorahosted.org/sssd/ticket/1069 --- src/util/find_uid.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/util/find_uid.c b/src/util/find_uid.c index e4d4ca8b..33c7c5ba 100644 --- a/src/util/find_uid.c +++ b/src/util/find_uid.c @@ -94,15 +94,17 @@ static errno_t get_uid_from_pid(const pid_t pid, uid_t *uid) if (error == ENOENT) { DEBUG(7, ("Proc file [%s] is not available anymore, continuing.\n", path)); - return EOK; + error = EOK; + goto fail_fd; } DEBUG(1, ("fstat failed [%d][%s].\n", error, strerror(error))); - return error; + goto fail_fd; } if (!S_ISREG(stat_buf.st_mode)) { DEBUG(1, ("not a regular file\n")); - return EINVAL; + error = EINVAL; + goto fail_fd; } while ((ret = read(fd, buf, BUFSIZE)) != 0) { @@ -112,7 +114,7 @@ static errno_t get_uid_from_pid(const pid_t pid, uid_t *uid) continue; } DEBUG(1, ("read failed [%d][%s].\n", error, strerror(error))); - return error; + goto fail_fd; } } @@ -156,6 +158,10 @@ static errno_t get_uid_from_pid(const pid_t pid, uid_t *uid) *uid = num; return EOK; + +fail_fd: + close(fd); + return error; } static errno_t name_to_pid(const char *name, pid_t *pid) -- cgit