cvs: gd(GD_2_0) /libgd gdft.c

[email protected] ("Pierre-Alain Joye")
Newsgroups php.gd.cvs
Message-ID <cvspajoye1172518242@cvsserver>
pajoye		Mon Feb 26 19:30:42 2007 UTC

  Modified files:              (Branch: GD_2_0)
    /gd/libgd	gdft.c 
  Log:
  - #48, Race condition in gdImageStringFTEx (cache)
  
  
http://cvs.php.net/viewvc.cgi/gd/libgd/gdft.c?r1=1.28.2.2&r2=1.28.2.3&diff_format=u
Index: gd/libgd/gdft.c
diff -u gd/libgd/gdft.c:1.28.2.2 gd/libgd/gdft.c:1.28.2.3
--- gd/libgd/gdft.c:1.28.2.2	Wed Feb  7 00:12:46 2007
+++ gd/libgd/gdft.c	Mon Feb 26 19:30:42 2007
@@ -217,6 +217,16 @@
   return strcmp(en1->name, en2->name);
 }
 
+extern int any2eucjp (char *, char *, unsigned int);
+
+/* Persistent font cache until explicitly cleared */
+/* Fonts can be used across multiple images */
+
+/* 2.0.16: thread safety (the font cache is shared) */
+gdMutexDeclare (gdFontCacheMutex);
+static gdCache_head_t *fontCache;
+static FT_Library library;
+
 #define Tcl_UniChar int
 #define TCL_UTF_MAX 3
 static int
@@ -767,24 +777,16 @@
 	      /* find antialised color */
 
 	      tc_key.bgcolor = *pixel;
+				gdMutexLock(gdFontCacheMutex);
 	      tc_elem = (tweencolor_t *) gdCacheGet (tc_cache, &tc_key);
 	      *pixel = tc_elem->tweencolor;
+				gdMutexUnlock(gdFontCacheMutex);
 	    }
 	}
     }
   return (char *) NULL;
 }
 
-extern int any2eucjp (char *, char *, unsigned int);
-
-/* Persistent font cache until explicitly cleared */
-/* Fonts can be used across multiple images */
-
-/* 2.0.16: thread safety (the font cache is shared) */
-gdMutexDeclare (gdFontCacheMutex);
-static gdCache_head_t *fontCache;
-static FT_Library library;
-
 BGD_DECLARE(void) gdFreeFontCache ()
 {
   gdFontCacheShutdown ();
@@ -794,11 +796,12 @@
 {
   if (fontCache)
     {
-      gdMutexShutdown (gdFontCacheMutex);
+			gdMutexLock(gdFontCacheMutex);
       gdCacheDelete (fontCache);
-      FT_Done_FreeType (library);
       /* 2.0.16: Gustavo Scotti: make sure we don't free this twice */
       fontCache = 0;
+      gdMutexShutdown (gdFontCacheMutex);
+      FT_Done_FreeType (library);
     }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.