cvs: gd /libgd NEWS /libgd/src gdxpm.c /libgd/tests/xpm CMakeLists.txt Makefile.am bug00185.c bug00185.xpm bug00185_damaged.xpm

[email protected] ("Takeshi Abe") Wed, 26 Nov 2008 19:20:21 -0000
Newsgroups php.gd.cvs
Message-ID <cvstabe1227727221@cvsserver>
tabe		Wed Nov 26 19:20:21 2008 UTC

  Added files:                 
    /gd/libgd/tests/xpm	bug00185.c bug00185.xpm bug00185_damaged.xpm 

  Modified files:              
    /gd/libgd	NEWS 
    /gd/libgd/src	gdxpm.c 
    /gd/libgd/tests/xpm	CMakeLists.txt Makefile.am 
  Log:
  fixed FS#185.
  
http://cvs.php.net/viewvc.cgi/gd/libgd/NEWS?r1=1.3&r2=1.4&diff_format=u
Index: gd/libgd/NEWS
diff -u gd/libgd/NEWS:1.3 gd/libgd/NEWS:1.4
--- gd/libgd/NEWS:1.3	Mon Nov  3 13:24:36 2008
+++ gd/libgd/NEWS	Wed Nov 26 19:20:21 2008
@@ -26,6 +26,7 @@
 173, Fixed the memory management in font_path() of gdft.c (Takeshi Abe)
 174, Fixed that font_path() in gdft.c breaks reentrancy (Takeshi Abe)
 181, Fixed gd_gif_out.c to enable proper interlace
+185, Fixed memory leaks in gdImageCreateFromXpm() (Takeshi Abe)
 
 GD 2.0.35 (2007-06-21)
 41, Fix valgrind error in gdImageFillTiled (Nuno Lopes) 
http://cvs.php.net/viewvc.cgi/gd/libgd/src/gdxpm.c?r1=1.12&r2=1.13&diff_format=u
Index: gd/libgd/src/gdxpm.c
diff -u gd/libgd/src/gdxpm.c:1.12 gd/libgd/src/gdxpm.c:1.13
--- gd/libgd/src/gdxpm.c:1.12	Thu Aug 21 11:34:05 2008
+++ gd/libgd/src/gdxpm.c	Wed Nov 26 19:20:21 2008
@@ -45,17 +45,17 @@
 
 	number = image.ncolors;
 	if(overflow2(sizeof(int), number)) {
-		return 0;
+		goto done;
 	}
 
 	colors = (int *)gdMalloc(sizeof(int) * number);
 	if(colors == NULL) {
-		return (0);
+		goto done;
 	}
 
 	if(!(im = gdImageCreate(image.width, image.height))) {
 		gdFree(colors);
-		return 0;
+		goto done;
 	}
 
 	for(i = 0; i < number; i++) {
@@ -160,6 +160,9 @@
 
 	gdFree(colors);
 
+ done:
+	XpmFreeXpmImage(&image);
+	XpmFreeXpmInfo(&info);
 	return im;
 }
 #endif /* HAVE_LIBXPM */
http://cvs.php.net/viewvc.cgi/gd/libgd/tests/xpm/CMakeLists.txt?r1=1.2&r2=1.3&diff_format=u
Index: gd/libgd/tests/xpm/CMakeLists.txt
diff -u gd/libgd/tests/xpm/CMakeLists.txt:1.2 gd/libgd/tests/xpm/CMakeLists.txt:1.3
--- gd/libgd/tests/xpm/CMakeLists.txt:1.2	Thu Aug 21 11:34:05 2008
+++ gd/libgd/tests/xpm/CMakeLists.txt	Wed Nov 26 19:20:21 2008
@@ -1,6 +1,7 @@
 
 SET(TESTS_FILES
 	bug00166
+	bug00185
 	color_name
 )
 
http://cvs.php.net/viewvc.cgi/gd/libgd/tests/xpm/Makefile.am?r1=1.2&r2=1.3&diff_format=u
Index: gd/libgd/tests/xpm/Makefile.am
diff -u gd/libgd/tests/xpm/Makefile.am:1.2 gd/libgd/tests/xpm/Makefile.am:1.3
--- gd/libgd/tests/xpm/Makefile.am:1.2	Thu Aug 21 11:34:05 2008
+++ gd/libgd/tests/xpm/Makefile.am	Wed Nov 26 19:20:21 2008
@@ -1,3 +1,3 @@
 ## Process this file with automake to produce Makefile.in -*-Makefile-*-
 
-EXTRA_DIST = CMakeLists.txt bug00166.c bug00166.xpm color_name.c color_name.xpm
+EXTRA_DIST = CMakeLists.txt bug00166.c bug00166.xpm bug00185.c bug00185.xpm bug00185_damaged.xpm color_name.c color_name.xpm

http://cvs.php.net/viewvc.cgi/gd/libgd/tests/xpm/bug00185.c?view=markup&rev=1.1
Index: gd/libgd/tests/xpm/bug00185.c
+++ gd/libgd/tests/xpm/bug00185.c
/* $Id: bug00185.c,v 1.1 2008/11/26 19:20:21 tabe Exp $ */
#include "gd.h"
#include <stdio.h>
#include <stdlib.h>
#include "gdtest.h"

/* To check memory leaks, run such as 'valgrind --leak-check=full ./bug00185' */
int
main()
{
  gdImagePtr im;
  char path[1024];

  sprintf(path, "%s/xpm/bug00185.xpm", GDTEST_TOP_DIR);
  im = gdImageCreateFromXpm(path);
  if (!im) return 1;
  gdImageDestroy(im);

  sprintf(path, "%s/xpm/bug00185_damaged.xpm", GDTEST_TOP_DIR);
  im = gdImageCreateFromXpm(path);
  if (!im) return 0;
  gdImageDestroy(im);

  return 2;
}

http://cvs.php.net/viewvc.cgi/gd/libgd/tests/xpm/bug00185.xpm?view=markup&rev=1.1
Index: gd/libgd/tests/xpm/bug00185.xpm
+++ gd/libgd/tests/xpm/bug00185.xpm
/* XPM */
static char * a[] = {
/* width height colors cpp */
"4 4 3 1",
"  c None",
"x c #ff00ff",
". c #ff0000",
/* pixels */
" ..x",
".xxx",
"xxx.",
"x.. "};

http://cvs.php.net/viewvc.cgi/gd/libgd/tests/xpm/bug00185_damaged.xpm?view=markup&rev=1.1
Index: gd/libgd/tests/xpm/bug00185_damaged.xpm
+++ gd/libgd/tests/xpm/bug00185_damaged.xpm
/* XPM */
static char * a[] = {
/* width height colors cpp */
"4 4 3 1",
"  c None",
"x c #ff00ff",
". c #ff0000",
/* pixels */
" ..x",
"xxx.",
"x.. "