Skip to content

babl_format_new: also free name to avoid leak

Andrzej Hunt requested to merge ahunt/babl:leaks-1 into master

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 (closed) 0x7f038605eec7 in babl_strdup /home/ahunt/git/babl/_build/../babl/babl-memory.c:296:9 #3 (closed) 0x7f038605110f in babl_format_new /home/ahunt/git/babl/_build/../babl/babl-format.c:376:17 #4 (closed) 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 (closed) 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).

Merge request reports