iliaa           Tue Nov 19 14:55:54 2002 EDT

  Modified files:              
    /php4/ext/gd        gdcache.c gdttf.c 
    /php4/ext/gd/libgd  gd_topal.c gdcache.c gdhelpers.h 
  Log:
  Addressed the issue of persistant allocation.
  Fixed bug #20470.
  Fixed a memory leak in gdttf.c that would happen when an error during 
  processing occures.
  
  
Index: php4/ext/gd/gdcache.c
diff -u php4/ext/gd/gdcache.c:1.5 php4/ext/gd/gdcache.c:1.6
--- php4/ext/gd/gdcache.c:1.5   Thu Oct 24 09:14:35 2002
+++ php4/ext/gd/gdcache.c       Tue Nov 19 14:55:54 2002
@@ -1,5 +1,5 @@
 /* 
- * $Id: gdcache.c,v 1.5 2002/10/24 13:14:35 sas Exp $
+ * $Id: gdcache.c,v 1.6 2002/11/19 19:55:54 iliaa Exp $
  *
  * Caches of pointers to user structs in which the least-recently-used 
  * element is replaced in the event of a cache miss after the cache has 
@@ -61,7 +61,7 @@
 {
        gdCache_head_t *head; 
 
-       head = (gdCache_head_t *)malloc(sizeof(gdCache_head_t));
+       head = (gdCache_head_t *)pemalloc(sizeof(gdCache_head_t), 1);
        head->mru = NULL;
        head->size = size;
        head->gdCacheTest = gdCacheTest;
@@ -80,9 +80,9 @@
                (*(head->gdCacheRelease))(elem->userdata);
                prev = elem;
                elem = elem->next;
-               free((char *)prev);
+               pefree((char *)prev, 1);
        }
-       free((char *)head);
+       pefree((char *)head, 1);
 }
 
 void *
@@ -114,7 +114,7 @@
                return NULL;
        }
        if (i < head->size) {  /* cache still growing - add new elem */
-               elem = (gdCache_element_t *)malloc(sizeof(gdCache_element_t));
+               elem = (gdCache_element_t *)pemalloc(sizeof(gdCache_element_t), 1);
        }
        else { /* cache full - replace least-recently-used */
                /* preveprev becomes new end of list */
Index: php4/ext/gd/gdttf.c
diff -u php4/ext/gd/gdttf.c:1.16 php4/ext/gd/gdttf.c:1.17
--- php4/ext/gd/gdttf.c:1.16    Sat Aug 11 12:38:30 2001
+++ php4/ext/gd/gdttf.c Tue Nov 19 14:55:54 2002
@@ -2,7 +2,7 @@
 /*                                          */
 /* John Ellson   [EMAIL PROTECTED]          */
 
-/* $Id: gdttf.c,v 1.16 2001/08/11 16:38:30 zeev Exp $ */
+/* $Id: gdttf.c,v 1.17 2002/11/19 19:55:54 iliaa Exp $ */
 
 #include "php.h"
 
@@ -334,15 +334,16 @@
        short                   platform, encoding;
        TSRMLS_FETCH();
 
-       a = (font_t *)malloc(sizeof(font_t));
+       a = (font_t *)pemalloc(sizeof(font_t), 1);
 #ifdef VIRTUAL_DIR
        /* a->fontname will be freed in fontRelease() later on */
        if (virtual_filepath(b->fontname, &a->fontname TSRMLS_CC)) {
                *error = "Could not find/open font";
+               pefree(a, 1);
                return NULL;
        }
 #else
-       a->fontname = (char *)malloc(strlen(b->fontname) + 1);
+       a->fontname = (char *)pemalloc(strlen(b->fontname) + 1, 1);
        strcpy(a->fontname, b->fontname);
 #endif
        a->ptsize = b->ptsize;
@@ -357,6 +358,7 @@
                else {
                        *error = "Could not read font";
                }
+               pefree(a, 1);
                return NULL;
        }
        /* get face properties and allocate preload arrays */
@@ -365,20 +367,19 @@
        /* create instance */
        if (TT_New_Instance(a->face, &a->instance)) {
                *error = "Could not create face instance";
+               pefree(a, 1);
                return NULL;
        }
        
        if (TT_Set_Instance_Resolutions(a->instance, RESOLUTION, RESOLUTION)) {
                *error = "Could not set device resolutions";
+               pefree(a, 1);
                return NULL;
-map_found = 0;
-a->have_char_map_Unicode = 0;
-a->have_char_map_Big5 = 0;
-a->have_char_map_Roman = 0;
        }
 
        if (TT_Set_Instance_CharSize(a->instance, (TT_F26Dot6)(a->ptsize*64))) {
                *error = "Could not set character size";
+               pefree(a, 1);
                return NULL;
        }
 
@@ -403,13 +404,14 @@
                        TT_Get_CharMap(a->face, i, &a->char_map_Roman);
                        a->have_char_map_Roman = 1;
                        map_found++;
-        }
+               }
        }
 
        if (! map_found) {
                *error = "Unable to find a CharMap that I can handle";
-        return NULL;
-    }
+               pefree(a, 1);
+               return NULL;
+       }
 
        a->matrix.xx = (TT_Fixed) (a->cos_a * (1<<16));
        a->matrix.yx = (TT_Fixed) (a->sin_a * (1<<16));
@@ -430,8 +432,8 @@
        gdCacheDelete(a->glyphCache);
        TT_Done_Instance(a->instance);
        TT_Close_Face(a->face);
-       free(a->fontname);
-       free( (char *)element );
+       pefree(a->fontname, 1);
+       pefree((char *)element, 1);
 }
 
 /********************************************************************/
@@ -458,7 +460,7 @@
        int                                     crect[8], xmin, xmax, ymin, ymax;
        double                          cos_a, sin_a;
 
-       a = (glyph_t *)malloc(sizeof(glyph_t));
+       a = (glyph_t *)pemalloc(sizeof(glyph_t), 1);
        a->character = b->character;
        a->hinting = b->hinting;
        a->gray_render = b->gray_render;
@@ -467,6 +469,7 @@
        /* create glyph container */
        if ((TT_New_Glyph(b->font->face, &a->glyph))) {
                *error = "Could not create glyph container";
+               pefree(a, 1);
                return NULL;
        }
 
@@ -483,6 +486,7 @@
        }
        if ((err=TT_Load_Glyph(b->font->instance, a->glyph, glyph_code, flags))) {
                *error = "TT_Load_Glyph problem";
+               pefree(a, 1);
                return NULL;
        }
 
@@ -540,7 +544,7 @@
 
        gdCacheDelete(a->bitmapCache);
        TT_Done_Glyph( a->glyph );
-       free( (char *)element );
+       pefree ((char *)element, 1);
 }
 
 /********************************************************************/
@@ -565,11 +569,11 @@
        bitmap_t                        *a;
        bitmapkey_t                     *b=(bitmapkey_t *)key;
 
-       a = (bitmap_t *)malloc(sizeof(bitmap_t));
+       a = (bitmap_t *)pemalloc(sizeof(bitmap_t), 1);
        a->xoffset = b->xoffset;
        a->yoffset = b->yoffset;
 
-       b->glyph->Bit.bitmap = a->bitmap = (char *)malloc(b->glyph->Bit.size);
+       b->glyph->Bit.bitmap = a->bitmap = (char *)pemalloc(b->glyph->Bit.size, 1);
        memset(a->bitmap, 0, b->glyph->Bit.size);
        /* render glyph */
        if (b->glyph->gray_render) {
@@ -588,8 +592,8 @@
 {
        bitmap_t *a=(bitmap_t *)element;
 
-       free( a->bitmap );
-       free( (char *)element );
+       pefree (a->bitmap, 1);
+       pefree ((char *)element, 1);
 }
 
 /********************************************************************/
@@ -615,7 +619,7 @@
        int pixel, npixel, bg, fg;
        gdImagePtr im;
    
-    a = (tweencolor_t *)malloc(sizeof(tweencolor_t));
+    a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1);
        pixel = a->pixel = b->pixel;
        bg = a->bgcolor = b->bgcolor;
        fg = a->fgcolor = b->fgcolor;
@@ -638,7 +642,7 @@
 static void
 tweenColorRelease(void *element)
 {   
-    free((char *)element);
+    pefree((char *)element, 1);
 }   
 
 /********************************************************************/
Index: php4/ext/gd/libgd/gd_topal.c
diff -u php4/ext/gd/libgd/gd_topal.c:1.8 php4/ext/gd/libgd/gd_topal.c:1.9
--- php4/ext/gd/libgd/gd_topal.c:1.8    Wed Oct 16 18:34:44 2002
+++ php4/ext/gd/libgd/gd_topal.c        Tue Nov 19 14:55:54 2002
@@ -1708,7 +1708,7 @@
                return -3; /* the images are meant to be the same dimensions */
        }
 
-       buf = (unsigned long *)malloc( sizeof(unsigned long) * 5 * im2->colorsTotal );
+       buf = (unsigned long *)gdMalloc( sizeof(unsigned long) * 5 * im2->colorsTotal 
+);
        memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal );
 
        for( x=0; x<im1->sx; x++ ) {
@@ -1735,6 +1735,6 @@
                        bp += 4;
                }
        }
-       free(buf);
+       gdFree(buf);
        return 0;
 }
Index: php4/ext/gd/libgd/gdcache.c
diff -u php4/ext/gd/libgd/gdcache.c:1.1 php4/ext/gd/libgd/gdcache.c:1.2
--- php4/ext/gd/libgd/gdcache.c:1.1     Fri Apr 12 22:03:08 2002
+++ php4/ext/gd/libgd/gdcache.c Tue Nov 19 14:55:54 2002
@@ -66,7 +66,7 @@
 {
   gdCache_head_t *head;
 
-  head = (gdCache_head_t *) gdMalloc (sizeof (gdCache_head_t));
+  head = (gdCache_head_t *) gdPMalloc(sizeof (gdCache_head_t));
   head->mru = NULL;
   head->size = size;
   head->gdCacheTest = gdCacheTest;
@@ -125,7 +125,7 @@
     }
   if (i < head->size)
     {                          /* cache still growing - add new elem */
-      elem = (gdCache_element_t *) gdMalloc (sizeof (gdCache_element_t));
+      elem = (gdCache_element_t *) gdPMalloc(sizeof (gdCache_element_t));
     }
   else
     {                          /* cache full - replace least-recently-used */
Index: php4/ext/gd/libgd/gdhelpers.h
diff -u php4/ext/gd/libgd/gdhelpers.h:1.4 php4/ext/gd/libgd/gdhelpers.h:1.5
--- php4/ext/gd/libgd/gdhelpers.h:1.4   Mon Nov 18 07:31:39 2002
+++ php4/ext/gd/libgd/gdhelpers.h       Tue Nov 19 14:55:54 2002
@@ -17,6 +17,8 @@
 #define gdRealloc(ptr, size)   erealloc(ptr, size)
 #define gdEstrdup(ptr)         estrdup(ptr)
 #define gdFree(ptr)            efree(ptr)
+#define gdPMalloc(ptr)         pemalloc(ptr, 1)
+#define gdPFree(ptr)           pefree(ptr, 1)
 
 #endif /* GDHELPERS_H */
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to