From: Jan Safranek Date: Wed, 24 Aug 2011 09:40:42 +0000 (+0200) Subject: libcgroup: Fixed leaked file descriptor when enumerating controllers X-Git-Tag: v0.38~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77f021bccf5e31acd7b15437c85e174e8b1e2dcf;p=thirdparty%2Flibcgroup.git libcgroup: Fixed leaked file descriptor when enumerating controllers Close the file when fgets fails. Signed-off-by: Jan Safranek Acked-by: Dhaval Giani --- diff --git a/src/api.c b/src/api.c index 0acf7876..5b2b518d 100644 --- a/src/api.c +++ b/src/api.c @@ -3822,6 +3822,7 @@ int cgroup_get_all_controller_begin(void **handle, struct controller_data *info) { FILE *proc_cgroup = NULL; char buf[FILENAME_MAX]; + int ret; if (!info) return ECGINVAL; @@ -3834,11 +3835,18 @@ int cgroup_get_all_controller_begin(void **handle, struct controller_data *info) if (!fgets(buf, FILENAME_MAX, proc_cgroup)) { last_errno = errno; + fclose(proc_cgroup); + *handle = NULL; return ECGOTHER; } *handle = proc_cgroup; - return cgroup_get_all_controller_next(handle, info); + ret = cgroup_get_all_controller_next(handle, info); + if (ret != 0) { + fclose(proc_cgroup); + *handle = NULL; + } + return ret; } static int pid_compare(const void *a, const void *b)