From: Michael Orlitzky Date: Mon, 7 Aug 2023 23:31:08 +0000 (-0400) Subject: io-svg.c: add a mutex around svgtiny_parse() X-Git-Tag: 0.0.1~10 X-Git-Url: http://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=82d44de402b3ac5fd468e559d3fdf1c2d08e1932;p=libsvgtiny-pixbuf.git io-svg.c: add a mutex around svgtiny_parse() This works around (what appears to be) a thread-safety issue in libwapcaplet: https://bugs.netsurf-browser.org/mantis/view.php?id=2857 --- diff --git a/io-svg.c b/io-svg.c index 68f8b4d..a588dcc 100644 --- a/io-svg.c +++ b/io-svg.c @@ -134,11 +134,23 @@ static diagram_t* svgtiny_diagram_from_buffer(const gchar* buffer, g_assert((int)width >= 0); g_assert((int)height >= 0); + + /* There's a thread-safety issue in libwapcaplet that can cause + * svgtiny_parse() to crash if you load lots of SVGs at once: + * + * https://bugs.netsurf-browser.org/mantis/view.php?id=2857 + * + * Putting a lock around svgtiny_parse() is a pretty simple solution + * and looks like it does the trick. + */ + static GMutex mutex; + g_mutex_lock(&mutex); code = svgtiny_parse(diagram, - buffer, - bytecount, "", - (int)width, - (int)height); + buffer, + bytecount, "", + (int)width, + (int)height); + g_mutex_unlock (&mutex); switch(code) { case svgtiny_OK: