oslib: do not call g_strdup from qemu_get_exec_dir

Just return the directory without requiring the caller to free it.
This also removes a bogus check for NULL in os_find_datadir and
module_load_one; g_strdup of a static variable cannot return NULL.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2020-08-18 12:11:02 +02:00
parent 05512f55aa
commit a4c13869f9
7 changed files with 20 additions and 27 deletions

View file

@ -172,7 +172,6 @@ bool module_load_one(const char *prefix, const char *lib_name)
#ifdef CONFIG_MODULES
char *fname = NULL;
char *exec_dir;
#ifdef CONFIG_MODULE_UPGRADES
char *version_dir;
#endif
@ -199,13 +198,12 @@ bool module_load_one(const char *prefix, const char *lib_name)
return true;
}
exec_dir = qemu_get_exec_dir();
search_dir = getenv("QEMU_MODULE_DIR");
if (search_dir != NULL) {
dirs[n_dirs++] = g_strdup_printf("%s", search_dir);
}
dirs[n_dirs++] = g_strdup_printf("%s", CONFIG_QEMU_MODDIR);
dirs[n_dirs++] = g_strdup_printf("%s", exec_dir ? : "");
dirs[n_dirs++] = g_strdup(qemu_get_exec_dir());
#ifdef CONFIG_MODULE_UPGRADES
version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),
@ -216,9 +214,6 @@ bool module_load_one(const char *prefix, const char *lib_name)
assert(n_dirs <= ARRAY_SIZE(dirs));
g_free(exec_dir);
exec_dir = NULL;
for (i = 0; i < n_dirs; i++) {
fname = g_strdup_printf("%s/%s%s",
dirs[i], module_name, CONFIG_HOST_DSOSUF);