提交 29c4a3c7 编写于 作者: D Daniel P. Berrangé

tests: avoid referencing stale readdir pointer

The contents of 'struct dirent' are only valid until the next call to
readdir() or closedir(). It is thus invalid to save a pointer to the
'd_name' field. Somehow this hasn't affected the test suite until
recently when FreeBSD 12 started showing use of uninitialized memory
resulting in test failures.
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 26badd13
......@@ -497,7 +497,7 @@ testQemuGetLatestCapsForArch(const char *arch,
char *tmp = NULL;
unsigned long maxver = 0;
unsigned long ver;
const char *maxname = NULL;
g_autofree char *maxname = NULL;
char *ret = NULL;
fullsuffix = g_strdup_printf("%s.%s", arch, suffix);
......@@ -522,7 +522,8 @@ testQemuGetLatestCapsForArch(const char *arch,
}
if (ver > maxver) {
maxname = ent->d_name;
g_free(maxname);
maxname = g_strdup(ent->d_name);
maxver = ver;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册