From: Pavel Hrdina Date: Mon, 13 Jan 2014 15:48:00 +0000 (+0100) Subject: Fix memory leak in securityselinuxlabeltest.c X-Git-Tag: CVE-2014-0028~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a0e74439910d474b5a442408bac051c3d488cff;p=thirdparty%2Flibvirt.git Fix memory leak in securityselinuxlabeltest.c Strings "file" and "context" may not be freed if "VIR_EXPAND_N" fails and it leads into memory leak. This has been found by coverity. Signed-off-by: Pavel Hrdina --- diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index d1fd92f8da..f98033de55 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -94,7 +94,7 @@ testSELinuxLoadFileList(const char *testname, goto cleanup; while (!feof(fp)) { - char *file, *context, *tmp; + char *file = NULL, *context = NULL, *tmp; if (!fgets(line, 1024, fp)) { if (!feof(fp)) goto cleanup; @@ -123,12 +123,13 @@ testSELinuxLoadFileList(const char *testname, tmp = strchr(context, '\n'); if (tmp) *tmp = '\0'; - } else { - context = NULL; } - if (VIR_EXPAND_N(*files, *nfiles, 1) < 0) + if (VIR_EXPAND_N(*files, *nfiles, 1) < 0) { + VIR_FREE(file); + VIR_FREE(context); goto cleanup; + } (*files)[(*nfiles)-1].file = file; (*files)[(*nfiles)-1].context = context;