From: Balbir Singh Date: Sat, 20 Sep 2008 00:54:04 +0000 (+0000) Subject: Fix a warning in api.c, where we ignore the fscanf value. X-Git-Tag: v0.34~221 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1450796033fc6c06694b4a4853f9c8c62e532564;p=thirdparty%2Flibcgroup.git Fix a warning in api.c, where we ignore the fscanf value. I've tested the patch by running the tests available in the tests directory. Signed-off-by: Balbir Singh git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@185 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- diff --git a/api.c b/api.c index 99037e8f..fef34c10 100644 --- a/api.c +++ b/api.c @@ -902,6 +902,7 @@ static char *cg_rd_ctrl_file(char *subsys, char *cgroup, char *file) char *value; char path[FILENAME_MAX]; FILE *ctrl_file; + int ret; if (!cg_build_path_locked(cgroup, path, subsys)) return NULL; @@ -919,7 +920,11 @@ static char *cg_rd_ctrl_file(char *subsys, char *cgroup, char *file) * using %as crashes when we try to read from files like * memory.stat */ - fscanf(ctrl_file, "%s", value); + ret = fscanf(ctrl_file, "%s", value); + if (ret == 0 || ret == EOF) { + free(value); + value = NULL; + } fclose(ctrl_file);