提交 7a0e7443 编写于 作者: P Pavel Hrdina

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: NPavel Hrdina <phrdina@redhat.com>
上级 67fbf129
...@@ -94,7 +94,7 @@ testSELinuxLoadFileList(const char *testname, ...@@ -94,7 +94,7 @@ testSELinuxLoadFileList(const char *testname,
goto cleanup; goto cleanup;
while (!feof(fp)) { while (!feof(fp)) {
char *file, *context, *tmp; char *file = NULL, *context = NULL, *tmp;
if (!fgets(line, 1024, fp)) { if (!fgets(line, 1024, fp)) {
if (!feof(fp)) if (!feof(fp))
goto cleanup; goto cleanup;
...@@ -123,12 +123,13 @@ testSELinuxLoadFileList(const char *testname, ...@@ -123,12 +123,13 @@ testSELinuxLoadFileList(const char *testname,
tmp = strchr(context, '\n'); tmp = strchr(context, '\n');
if (tmp) if (tmp)
*tmp = '\0'; *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; goto cleanup;
}
(*files)[(*nfiles)-1].file = file; (*files)[(*nfiles)-1].file = file;
(*files)[(*nfiles)-1].context = context; (*files)[(*nfiles)-1].context = context;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册