diff mbox series

[v2,06/13] vl: fix direct firmware directories leak

Message ID 20171215150659.1811-7-marcandre.lureau@redhat.com
State New
Headers show
Series Various build-sys and ASAN related fixes | expand

Commit Message

Marc-André Lureau Dec. 15, 2017, 3:06 p.m. UTC
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 <marcandre.lureau@redhat.com>
---
 vl.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Eric Blake Dec. 15, 2017, 6:30 p.m. UTC | #1
On 12/15/2017 09:06 AM, Marc-André Lureau wrote:
> 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 <marcandre.lureau@redhat.com>
> ---
>  vl.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox series

Patch

diff --git a/vl.c b/vl.c
index fc8bd9372f..282dc79d82 100644
--- a/vl.c
+++ b/vl.c
@@ -2319,7 +2319,7 @@  static void qemu_add_data_dir(const char *path)
             return; /* duplicate */
         }
     }
-    data_dir[data_dir_idx++] = path;
+    data_dir[data_dir_idx++] = g_strdup(path);
 }
 
 static inline bool nonempty_str(const char *str)
@@ -3080,7 +3080,7 @@  int main(int argc, char **argv, char **envp)
     Error *main_loop_err = NULL;
     Error *err = NULL;
     bool list_data_dirs = false;
-    char **dirs;
+    char *dir, **dirs;
     typedef struct BlockdevOptions_queue {
         BlockdevOptions *bdo;
         Location loc;
@@ -4268,9 +4268,12 @@  int main(int argc, char **argv, char **envp)
     for (i = 0; dirs[i] != NULL; i++) {
         qemu_add_data_dir(dirs[i]);
     }
+    g_strfreev(dirs);
 
     /* try to find datadir relative to the executable path */
-    qemu_add_data_dir(os_find_datadir());
+    dir = os_find_datadir();
+    qemu_add_data_dir(dir);
+    g_free(dir);
 
     /* add the datadir specified when building */
     qemu_add_data_dir(CONFIG_QEMU_DATADIR);