]> gitweb.michael.orlitzky.com - libsvgtiny-pixbuf.git/blobdiff - io-svg.c
README: wording tweaks
[libsvgtiny-pixbuf.git] / io-svg.c
index 68f8b4dc4e7aa9e454256e1a6589c4628d530dc5..95a0812cf9e18b57e61af10b8bf8ec5db3304ea6 100644 (file)
--- a/io-svg.c
+++ b/io-svg.c
@@ -1,13 +1,15 @@
 #include <string.h> /* memcpy, memset */
 
 #include <cairo.h>
-#include <gdk/gdk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h> /* includes glib.h */
 #include <glib/gprintf.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <svgtiny.h>
 
+/* This "header" includes extra code that we've copy/pasted from GDK */
+#include "gdk_pixbuf_get_from_surface.h"
+
 /*
  * The width and height of the viewport that we'll render the SVG
  * into. The final "picture" may not actually be this size; based on
@@ -134,11 +136,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: