summaryrefslogtreecommitdiff
path: root/ext/gd
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2002-11-19 19:55:54 +0000
committerIlia Alshanetsky <iliaa@php.net>2002-11-19 19:55:54 +0000
commit11e7f6278d3365fb6cd8a4caa393e856b54e9f5a (patch)
tree2a094fcf81e80663911acce55b77fcbf328ad140 /ext/gd
parent010fd97aa52214e5dce5a10e12e063c2f835b516 (diff)
downloadphp-git-11e7f6278d3365fb6cd8a4caa393e856b54e9f5a.tar.gz
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.
Diffstat (limited to 'ext/gd')
-rw-r--r--ext/gd/gdcache.c8
-rw-r--r--ext/gd/gdttf.c42
-rw-r--r--ext/gd/libgd/gd_topal.c4
-rw-r--r--ext/gd/libgd/gdcache.c4
-rw-r--r--ext/gd/libgd/gdhelpers.h2
5 files changed, 33 insertions, 27 deletions
diff --git a/ext/gd/gdcache.c b/ext/gd/gdcache.c
index 7791d1bbf5..55ad98ff67 100644
--- a/ext/gd/gdcache.c
+++ b/ext/gd/gdcache.c
@@ -61,7 +61,7 @@ gdCacheCreate(
{
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 @@ gdCacheDelete( gdCache_head_t *head )
(*(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 @@ gdCacheGet( gdCache_head_t *head, void *keydata )
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 */
diff --git a/ext/gd/gdttf.c b/ext/gd/gdttf.c
index 393f0bdbf7..84c73c0efa 100644
--- a/ext/gd/gdttf.c
+++ b/ext/gd/gdttf.c
@@ -334,15 +334,16 @@ fontFetch ( char **error, void *key )
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 @@ fontFetch ( char **error, void *key )
else {
*error = "Could not read font";
}
+ pefree(a, 1);
return NULL;
}
/* get face properties and allocate preload arrays */
@@ -365,20 +367,19 @@ fontFetch ( char **error, void *key )
/* 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 @@ a->have_char_map_Roman = 0;
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 @@ fontRelease( void *element )
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 @@ glyphFetch ( char **error, void *key )
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 @@ glyphFetch ( char **error, void *key )
/* 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 @@ glyphFetch ( char **error, void *key )
}
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 @@ glyphRelease( void *element )
gdCacheDelete(a->bitmapCache);
TT_Done_Glyph( a->glyph );
- free( (char *)element );
+ pefree ((char *)element, 1);
}
/********************************************************************/
@@ -565,11 +569,11 @@ bitmapFetch ( char **error, void *key )
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 @@ bitmapRelease( void *element )
{
bitmap_t *a=(bitmap_t *)element;
- free( a->bitmap );
- free( (char *)element );
+ pefree (a->bitmap, 1);
+ pefree ((char *)element, 1);
}
/********************************************************************/
@@ -615,7 +619,7 @@ tweenColorFetch (char **error, void *key)
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 @@ tweenColorFetch (char **error, void *key)
static void
tweenColorRelease(void *element)
{
- free((char *)element);
+ pefree((char *)element, 1);
}
/********************************************************************/
diff --git a/ext/gd/libgd/gd_topal.c b/ext/gd/libgd/gd_topal.c
index 7e2de25fc5..e8358d577e 100644
--- a/ext/gd/libgd/gd_topal.c
+++ b/ext/gd/libgd/gd_topal.c
@@ -1708,7 +1708,7 @@ gdImageColorMatch (gdImagePtr im1, gdImagePtr im2)
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 @@ gdImageColorMatch (gdImagePtr im1, gdImagePtr im2)
bp += 4;
}
}
- free(buf);
+ gdFree(buf);
return 0;
}
diff --git a/ext/gd/libgd/gdcache.c b/ext/gd/libgd/gdcache.c
index e4770f5ba9..2c8e6d5c8b 100644
--- a/ext/gd/libgd/gdcache.c
+++ b/ext/gd/libgd/gdcache.c
@@ -66,7 +66,7 @@ gdCacheCreate (
{
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 @@ gdCacheGet (gdCache_head_t * head, void *keydata)
}
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 */
diff --git a/ext/gd/libgd/gdhelpers.h b/ext/gd/libgd/gdhelpers.h
index bb689cbefe..32bd940a17 100644
--- a/ext/gd/libgd/gdhelpers.h
+++ b/ext/gd/libgd/gdhelpers.h
@@ -17,6 +17,8 @@ extern char *gd_strtok_r(char *s, char *sep, char **state);
#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 */