]> Pileus Git - ~andy/gtk/commitdiff
Make libpng use g_malloc instead of system malloc.
authorMatthias Clasen <matthiasc@src.gnome.org>
Tue, 26 Mar 2002 23:17:31 +0000 (23:17 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 26 Mar 2002 23:17:31 +0000 (23:17 +0000)
* io-png.c (gdk_pixbuf__png_image_load,
gdk_pixbuf__png_image_begin_load): Make libpng use g_malloc
instead of system malloc.

gdk-pixbuf/ChangeLog
gdk-pixbuf/io-png.c

index 0d79705001c647de3081efa35c2f1edd2b95da06..c7e368af0bc7e628a856a6b7a70091ccde45a963 100644 (file)
@@ -1,3 +1,9 @@
+2002-03-27  Matthias Clasen  <maclas@gmx.de>
+
+       * io-png.c (gdk_pixbuf__png_image_load,
+       gdk_pixbuf__png_image_begin_load): Make libpng use g_malloc
+       instead of system malloc. 
+
 2002-03-26  Matthias Clasen  <maclas@gmx.de>
 
        * io-tiff.c (tiff_image_parse): Don't leak pixbuf on error.
index c287654d12d5a52d579d18f05b726b345777e433..3038e74e28b34d995c5ef275d3cbbd7ad3d1f950 100644 (file)
@@ -222,6 +222,18 @@ png_text_to_pixbuf_option (png_text   text_ptr,
         }
 }
 
+static png_voidp
+png_malloc_callback (png_structp o, png_size_t size)
+{
+        return g_try_malloc (size);
+}
+
+static void
+png_free_callback (png_structp o, png_voidp x)
+{
+        g_free (x);
+}
+
 /* Shared library entry point */
 static GdkPixbuf *
 gdk_pixbuf__png_image_load (FILE *f, GError **error)
@@ -237,10 +249,20 @@ gdk_pixbuf__png_image_load (FILE *f, GError **error)
         gint    num_texts;
         gchar **options = NULL;
 
+#ifdef PNG_USER_MEM_SUPPORTED
+       png_ptr = png_create_read_struct_2 (PNG_LIBPNG_VER_STRING,
+                                            error,
+                                            png_simple_error_callback,
+                                            png_simple_warning_callback,
+                                            NULL, 
+                                            png_malloc_callback, 
+                                            png_free_callback);
+#else
        png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
                                           error,
                                           png_simple_error_callback,
                                           png_simple_warning_callback);
+#endif
        if (!png_ptr)
                return NULL;
 
@@ -421,12 +443,20 @@ gdk_pixbuf__png_image_begin_load (ModulePreparedNotifyFunc prepare_func,
         
         /* Create the main PNG context struct */
 
-               
+#ifdef PNG_USER_MEM_SUPPORTED
+        lc->png_read_ptr = png_create_read_struct_2 (PNG_LIBPNG_VER_STRING,
+                                                     lc, /* error/warning callback data */
+                                                     png_error_callback,
+                                                     png_warning_callback,
+                                                     NULL,
+                                                     png_malloc_callback,
+                                                     png_free_callback);
+#else
         lc->png_read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
                                                   lc, /* error/warning callback data */
                                                   png_error_callback,
                                                   png_warning_callback);
-
+#endif
         if (lc->png_read_ptr == NULL) {
                 g_free(lc);
                 /* error callback should have set the error */