Skip to content
  • Stefano Garzarella's avatar
    b6d003db
    cutils: fix memory leak in get_relocated_path() · b6d003db
    Stefano Garzarella authored
    
    
    get_relocated_path() allocates a GString object and returns the
    character data (C string) to the caller without freeing the memory
    allocated for that object as reported by valgrind:
    
      24 bytes in 1 blocks are definitely lost in loss record 2,805 of 6,532
         at 0x4839809: malloc (vg_replace_malloc.c:307)
         by 0x55AABB8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
         by 0x55C2481: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
         by 0x55C4827: g_string_sized_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
         by 0x55C4CEA: g_string_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
         by 0x906314: get_relocated_path (cutils.c:1036)
         by 0x6E1F77: qemu_read_default_config_file (vl.c:2122)
         by 0x6E1F77: qemu_init (vl.c:2687)
         by 0x3E3AF8: main (main.c:49)
    
    Let's use g_string_free(gstring, false) to free only the GString object
    and transfer the ownership of the character data to the caller.
    
    Fixes: f4f5ed2c ("cutils: introduce get_relocated_path")
    Signed-off-by: default avatarStefano Garzarella <sgarzare@redhat.com>
    Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
    Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Message-Id: <20210412170255.231406-1-sgarzare@redhat.com>
    Signed-off-by: default avatarLaurent Vivier <laurent@vivier.eu>
    b6d003db
    cutils: fix memory leak in get_relocated_path()
    Stefano Garzarella authored
    
    
    get_relocated_path() allocates a GString object and returns the
    character data (C string) to the caller without freeing the memory
    allocated for that object as reported by valgrind:
    
      24 bytes in 1 blocks are definitely lost in loss record 2,805 of 6,532
         at 0x4839809: malloc (vg_replace_malloc.c:307)
         by 0x55AABB8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
         by 0x55C2481: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
         by 0x55C4827: g_string_sized_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
         by 0x55C4CEA: g_string_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
         by 0x906314: get_relocated_path (cutils.c:1036)
         by 0x6E1F77: qemu_read_default_config_file (vl.c:2122)
         by 0x6E1F77: qemu_init (vl.c:2687)
         by 0x3E3AF8: main (main.c:49)
    
    Let's use g_string_free(gstring, false) to free only the GString object
    and transfer the ownership of the character data to the caller.
    
    Fixes: f4f5ed2c ("cutils: introduce get_relocated_path")
    Signed-off-by: default avatarStefano Garzarella <sgarzare@redhat.com>
    Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
    Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Message-Id: <20210412170255.231406-1-sgarzare@redhat.com>
    Signed-off-by: default avatarLaurent Vivier <laurent@vivier.eu>
Loading