From: Øyvind Kolås Date: Sun, 23 Jan 2022 22:35:34 +0000 (+0100) Subject: babl: avoid using half initialized LUTs when used from threads X-Git-Tag: archive/raspbian/1%0.1.106-3+rpi1^2~15^2~4^2~43 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=da2dc167d0a9a522adfcd3ef609d6ff599b8036b;p=babl.git babl: avoid using half initialized LUTs when used from threads --- diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c index e372d4f..7d9e825 100644 --- a/babl/babl-fish-path.c +++ b/babl/babl-fish-path.c @@ -721,8 +721,7 @@ babl_fish_path_process (const Babl *babl, ((Babl*)babl)->fish.pixels += n; if (!lut && babl->fish.pixels > 256 * 128) { - ((Babl*)babl)->fish_path.u8_lut = malloc (256 * 256 * 256 * 4); - lut = (uint32_t*)babl->fish_path.u8_lut; + lut = malloc (256 * 256 * 256 * 4); if (babl->fish_path.source_bpp == 8) { uint64_t *lut_in = malloc (256 * 256 * 256 * 8); @@ -758,6 +757,18 @@ babl_fish_path_process (const Babl *babl, babl->fish_path.dest_bpp, 256*256*256); } + // XXX : there is still a micro race, if lost we should only + // leak a LUT not produce wrong results. + if (babl->fish_path.u8_lut == NULL) + { + (((Babl*)babl)->fish_path.u8_lut) = (uint8_t*)lut; + + } + else + { + free (lut); + lut = (uint32_t*)babl->fish_path.u8_lut; + } } if (lut) {