From da2dc167d0a9a522adfcd3ef609d6ff599b8036b Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sun, 23 Jan 2022 23:35:34 +0100 Subject: [PATCH] babl: avoid using half initialized LUTs when used from threads --- babl/babl-fish-path.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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) { -- 2.30.2