cvs: gd(GD_2_0) /libgd/src gdft.c

[email protected] ("Takeshi Abe") Wed, 25 Mar 2009 17:02:17 -0000
Newsgroups php.gd.cvs
Message-ID <cvstabe1238000537@cvsserver>
tabe		Wed Mar 25 17:02:17 2009 UTC

  Modified files:              (Branch: GD_2_0)
    /gd/libgd/src	gdft.c 
  Log:
  MFH: fixed memory leaks through failure
  
http://cvs.php.net/viewvc.cgi/gd/libgd/src/gdft.c?r1=1.28.2.11&r2=1.28.2.12&diff_format=u
Index: gd/libgd/src/gdft.c
diff -u gd/libgd/src/gdft.c:1.28.2.11 gd/libgd/src/gdft.c:1.28.2.12
--- gd/libgd/src/gdft.c:1.28.2.11	Sat Aug  2 14:43:45 2008
+++ gd/libgd/src/gdft.c	Wed Mar 25 17:02:17 2009
@@ -1077,6 +1077,7 @@
   else
     {
       /* No character set found! */
+      gdCacheDelete (tc_cache);
       gdMutexUnlock (gdFontCacheMutex);
       return "No character set found";
     }
@@ -1245,7 +1246,11 @@
 			xshow_alloc = 100;
 			strex->xshow = gdMalloc(xshow_alloc);
 			if (!strex->xshow) {
-				return 0;
+				if (tmpstr)
+				  gdFree (tmpstr);
+				gdCacheDelete (tc_cache);
+				gdMutexUnlock (gdFontCacheMutex);
+				return "Problem allocating memory";
 			}
 			xshow_pos = 0;
 	  } 
@@ -1253,7 +1258,11 @@
 		xshow_alloc += 100;
 		strex->xshow = gdRealloc(strex->xshow, xshow_alloc);
 		if (!strex->xshow) {
-			return 0;
+			if (tmpstr)
+			  gdFree (tmpstr);
+			gdCacheDelete (tc_cache);
+			gdMutexUnlock (gdFontCacheMutex);
+			return "Problem allocating memory";
 		}
 	}
 	  xshow_pos += sprintf(strex->xshow + xshow_pos, "%g ",
@@ -1265,6 +1274,8 @@
       err = FT_Load_Glyph (face, glyph_index, render_mode);
       if (err)
 	{
+	  if (tmpstr)
+	    gdFree (tmpstr);
 	  gdCacheDelete (tc_cache);
 	  gdMutexUnlock (gdFontCacheMutex);
 	  return "Problem loading glyph";
@@ -1318,6 +1329,8 @@
           err = FT_Load_Glyph (face, glyph_index, render_mode);
           if (err)
 	    {
+	      if (tmpstr)
+	        gdFree (tmpstr);
 	      gdCacheDelete (tc_cache);
 	      gdMutexUnlock (gdFontCacheMutex);
 	      return "Problem loading glyph";
@@ -1331,6 +1344,8 @@
 	      err = FT_Glyph_To_Bitmap (&image, ft_render_mode_normal, 0, 1);
 	      if (err)
 		{
+		  if (tmpstr)
+		    gdFree (tmpstr);
 		  gdCacheDelete (tc_cache);
 		  gdMutexUnlock (gdFontCacheMutex);
 		  return "Problem rendering glyph";