babl_format_new: also free doc to plug leak
authorAndrzej Hunt <andrzej@ahunt.org>
Sat, 4 Sep 2021 11:43:29 +0000 (13:43 +0200)
committerØyvind Kolås <pippin@gimp.org>
Sat, 19 Feb 2022 17:02:56 +0000 (18:02 +0100)
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

index c9a117560a1d2836456dac6979d476482ff5847e..982b851e2d5db8bda4f6182f26ed1c9e80cd4322 100644 (file)
@@ -510,6 +510,7 @@ babl_format_new (const void *first_arg,
                     "with different content!", name);
 
       babl_free (name);
+      babl_free (doc);
       return babl;
     }