[babl] babl_format_new: also free doc to plug leak



commit 475ce06f94f9c90f0a0a83772b5d22e7ea3f26d8
Author: Andrzej Hunt <andrzej ahunt org>
Date:   Sat Sep 4 13:43:29 2021 +0200

    babl_format_new: also free doc to plug leak
    
    doc and name are allocated via babl_strdup, hence if we don't use them
    we need to free both of them - therefore add a free(doc) to match the
    existing free(name).
    
    format_new (called just below) transfers ownership of doc, hence it's
    correct not to free doc in the case where we're instantiating a new
    format - whereas name is copied within format_new, and therefore needs to be
    free'd in either scenario.
    
    Leak seen while running gimp+babl built with ASAN:
    
      Direct leak of 99 byte(s) in 1 object(s) allocated from:
        #0 0x5e87cd in malloc 
/home/abuild/rpmbuild/BUILD/llvm-12.0.0.src/build/../projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
        #1 0x7f038605e2b8 in babl_malloc /home/ahunt/git/babl/_build/../babl/babl-memory.c:115:9
        #2 0x7f038605eec7 in babl_strdup /home/ahunt/git/babl/_build/../babl/babl-memory.c:296:9
        #3 0x7f038605110f in babl_format_new /home/ahunt/git/babl/_build/../babl/babl-format.c:376:17
        #4 0x7f037313a432 in init /home/ahunt/git/babl/_build/../extensions/cairo.c:569:25
        #5 0x7f03860412a1 in babl_extension_load /home/ahunt/git/babl/_build/../babl/babl-extension.c:226:7
        #6 0x7f0386040d1c in babl_extension_load_dir 
/home/ahunt/git/babl/_build/../babl/babl-extension.c:268:19
        #7 0x7f03860409a8 in babl_extension_load_dir_list 
/home/ahunt/git/babl/_build/../babl/babl-extension.c:338:17
        #8 0x7f038607d6cd in babl_init /home/ahunt/git/babl/_build/../babl/babl.c:154:7
        #9 0x7f0386bce5ab in gegl_post_parse_hook /home/ahunt/git/gegl/_build/../gegl/gegl-init.c:542:3
        #10 0x7f03844aad8a in g_option_context_parse /home/ahunt/git/glib/_build/../glib/goption.c:2228:12
        #11 0x7f0386bce381 in gegl_init /home/ahunt/git/gegl/_build/../gegl/gegl-init.c:189:8
        #12 0xef1f6b in gimp_init_for_testing /home/ahunt/git/gimp/app/tests.c:69:3
        [...]
    
    SUMMARY: AddressSanitizer: 99 byte(s) leaked in 1 allocation(s).

 babl/babl-format.c | 1 +
 1 file changed, 1 insertion(+)
---
diff --git a/babl/babl-format.c b/babl/babl-format.c
index c9a117560..982b851e2 100644
--- a/babl/babl-format.c
+++ b/babl/babl-format.c
@@ -510,6 +510,7 @@ babl_format_new (const void *first_arg,
                     "with different content!", name);
 
       babl_free (name);
+      babl_free (doc);
       return babl;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]