diff options
author | Jan Zeleny <jzeleny@redhat.com> | 2011-11-04 04:08:36 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2011-11-07 08:57:17 -0500 |
commit | 21386a358f0850b660139fe6db2bdd2e14c8a4ef (patch) | |
tree | 18588f8294ea8131554279d87a0986ebca4ff2e5 /src | |
parent | fd21ca460115a5d51d0db6e5ac759b8aff51ab99 (diff) | |
download | sssd-21386a358f0850b660139fe6db2bdd2e14c8a4ef.tar.gz sssd-21386a358f0850b660139fe6db2bdd2e14c8a4ef.tar.bz2 sssd-21386a358f0850b660139fe6db2bdd2e14c8a4ef.zip |
Fixed possible resource leak in get_uid_from_pid()
https://fedorahosted.org/sssd/ticket/1069
Diffstat (limited to 'src')
-rw-r--r-- | src/util/find_uid.c | 14 |
1 files 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) |