Skip to content

Commit 3547112

Browse files
elmarcobonzini
authored andcommitted
vl: fix direct firmware directories leak
Note that data_dir[] will now point to allocated strings. Fixes: Direct leak of 16 byte(s) in 1 object(s) allocated from: #0 0x7f1448181850 in malloc (/lib64/libasan.so.4+0xde850) #1 0x7f1446ed8f0c in g_malloc ../glib/gmem.c:94 #2 0x7f1446ed91cf in g_malloc_n ../glib/gmem.c:331 #3 0x7f1446ef739a in g_strsplit ../glib/gstrfuncs.c:2364 #4 0x55cf276439d7 in main /home/elmarco/src/qq/vl.c:4311 #5 0x7f143dfad039 in __libc_start_main (/lib64/libc.so.6+0x21039) Signed-off-by: Marc-André Lureau <[email protected]> Reviewed-by: Eric Blake <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 87c258c commit 3547112

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

vl.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -2318,7 +2318,7 @@ static void qemu_add_data_dir(const char *path)
23182318
return; /* duplicate */
23192319
}
23202320
}
2321-
data_dir[data_dir_idx++] = path;
2321+
data_dir[data_dir_idx++] = g_strdup(path);
23222322
}
23232323

23242324
static inline bool nonempty_str(const char *str)
@@ -3078,7 +3078,7 @@ int main(int argc, char **argv, char **envp)
30783078
Error *main_loop_err = NULL;
30793079
Error *err = NULL;
30803080
bool list_data_dirs = false;
3081-
char **dirs;
3081+
char *dir, **dirs;
30823082
typedef struct BlockdevOptions_queue {
30833083
BlockdevOptions *bdo;
30843084
Location loc;
@@ -4181,9 +4181,12 @@ int main(int argc, char **argv, char **envp)
41814181
for (i = 0; dirs[i] != NULL; i++) {
41824182
qemu_add_data_dir(dirs[i]);
41834183
}
4184+
g_strfreev(dirs);
41844185

41854186
/* try to find datadir relative to the executable path */
4186-
qemu_add_data_dir(os_find_datadir());
4187+
dir = os_find_datadir();
4188+
qemu_add_data_dir(dir);
4189+
g_free(dir);
41874190

41884191
/* add the datadir specified when building */
41894192
qemu_add_data_dir(CONFIG_QEMU_DATADIR);

0 commit comments

Comments
 (0)