Close the file when fgets fails. Signed-off-by: Jan Safranek <jsafr...@redhat.com> ---
src/api.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/src/api.c b/src/api.c index 0acf787..5b2b518 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) ------------------------------------------------------------------------------ EMC VNX: the world's simplest storage, starting under $10K The only unified storage solution that offers unified management Up to 160% more powerful than alternatives and 25% more efficient. Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel