cvs: /php3/functions pdf.c
| From: | Uwe Steinmann | Date: | Tue, 14 Sep 1999 10:02:17 +0000 |
| Subject: | cvs: /php3/functions pdf.c | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-10887@lists.php.net to get a copy of this message | ||
steinm Tue Sep 14 06:02:17 1999 EDT
Modified files:
/php3/functions pdf.c
Log:
- fixed memory leak in pdf_open_memory_image
I'm not very happy with this solution and already in contact
with the author of pdflib to find a better way.
Index: php3/functions/pdf.c
diff -u php3/functions/pdf.c:1.50 php3/functions/pdf.c:1.51
--- php3/functions/pdf.c:1.50 Thu Sep 9 02:40:55 1999
+++ php3/functions/pdf.c Tue Sep 14 06:02:16 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pdf.c,v 1.50 1999/09/09 06:40:55 steinm Exp $ */
+/* $Id: pdf.c,v 1.51 1999/09/14 10:02:16 steinm Exp $ */
/* pdflib 0.6 is subject to the ALADDIN FREE PUBLIC LICENSE.
Copyright (C) 1997 Thomas Merz. */
@@ -58,6 +58,13 @@
#if HAVE_PDFLIB
+#if HAVE_PDFLIB2
+typedef struct my_pdf_image_struct{
+ char *buffer;
+ int image;
+} MY_PDF_IMAGE;
+#endif
+
#ifdef THREAD_SAFE
DWORD PDFlibTls;
static int numthreads=0;
@@ -191,12 +198,16 @@
#endif
#if HAVE_PDFLIB2
-static void _free_pdf_image(int image)
+/*static void _free_pdf_image(int image)*/
+static void _free_pdf_image(MY_PDF_IMAGE *image)
#else
static void _free_pdf_image(PDF_image *image)
#endif
{
#if HAVE_PDFLIB2
+ if(image->buffer)
+ efree(image->buffer);
+ efree(image);
#else
/* In pdflib 0.6 the first parameter isn't used in any of the image
close functions. It later versions it is the PDF doc.
@@ -2152,6 +2163,7 @@
int id, type;
#if HAVE_PDFLIB2
int pdf_image;
+ MY_PDF_IMAGE *my_pdf_image;
#else
PDF_image *pdf_image;
#endif
@@ -2178,7 +2190,10 @@
RETURN_FALSE;
}
- id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image));
+ my_pdf_image = emalloc(sizeof(MY_PDF_IMAGE));
+ my_pdf_image->buffer = NULL;
+ my_pdf_image->image = pdf_image;
+ id = php3_list_insert((void *) my_pdf_image,PDF_GLOBAL(le_pdf_image));
RETURN_LONG(id);
}
/* }}} */
@@ -2190,6 +2205,7 @@
int id, type;
#if HAVE_PDFLIB2
int pdf_image;
+ MY_PDF_IMAGE *my_pdf_image;
#else
PDF_image *pdf_image;
#endif
@@ -2216,7 +2232,10 @@
RETURN_FALSE;
}
- id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image));
+ my_pdf_image = (MY_PDF_IMAGE *)emalloc(sizeof(MY_PDF_IMAGE));
+ my_pdf_image->buffer = NULL;
+ my_pdf_image->image = pdf_image;
+ id = php3_list_insert((void *) my_pdf_image,PDF_GLOBAL(le_pdf_image));
RETURN_LONG(id);
}
/* }}} */
@@ -2230,6 +2249,7 @@
int argc;
int i, j, id, gid, type, color, count;
int pdf_image;
+ MY_PDF_IMAGE *my_pdf_image;
gdImagePtr im;
unsigned char *buffer, *ptr;
PDF *pdf;
@@ -2281,7 +2301,10 @@
RETURN_FALSE;
}
- id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image));
+ my_pdf_image = emalloc(sizeof(MY_PDF_IMAGE));
+ my_pdf_image->buffer = buffer;
+ my_pdf_image->image = pdf_image;
+ id = php3_list_insert((void *) my_pdf_image,PDF_GLOBAL(le_pdf_image));
RETURN_LONG(id);
}
/* }}} */
@@ -2295,6 +2318,7 @@
int id, type;
#if HAVE_PDFLIB2
int pdf_image;
+ MY_PDF_IMAGE *my_pdf_image;
#else
PDF_image *pdf_image;
#endif
@@ -2324,8 +2348,8 @@
convert_to_long(arg2);
id=arg2->value.lval;
#if HAVE_PDFLIB2
- pdf_image = (int) php3_list_find(id,&type);
- if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
+ my_pdf_image = (MY_PDF_IMAGE *) php3_list_find(id,&type);
+ if(my_pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
#else
pdf_image = php3_list_find(id,&type);
if(!pdf_image || type!=PDF_GLOBAL(le_pdf_image)) {
@@ -2335,7 +2359,9 @@
}
#if HAVE_PDFLIB2
- PDF_close_image(pdf, pdf_image);
+ PDF_close_image(pdf, my_pdf_image->image);
+ php3_list_delete(id);
+// if(my_pdf_image->buffer) efree(my_pdf_image->buffer);
#else
/* See comment in _free_pdf_image() */
PDF_close_image(NULL, pdf_image);
@@ -2352,6 +2378,7 @@
int id, type;
#if HAVE_PDFLIB2
int pdf_image;
+ MY_PDF_IMAGE *my_pdf_image;
#else
PDF_image *pdf_image;
#endif
@@ -2373,8 +2400,9 @@
convert_to_long(arg2);
id=arg2->value.lval;
#if HAVE_PDFLIB2
- pdf_image = (int) php3_list_find(id,&type);
- if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
+/* pdf_image = (int) php3_list_find(id,&type);*/
+ my_pdf_image = (MY_PDF_IMAGE *) php3_list_find(id,&type);
+ if(my_pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
#else
pdf_image = php3_list_find(id,&type);
if(!pdf_image || type!=PDF_GLOBAL(le_pdf_image)) {
@@ -2387,7 +2415,7 @@
convert_to_double(arg4);
convert_to_double(arg5);
- PDF_place_image(pdf, pdf_image, (float) arg3->value.dval, (float) arg4->value.dval,
arg5->value.dval);
+ PDF_place_image(pdf, my_pdf_image->image, (float) arg3->value.dval, (float)
arg4->value.dval, arg5->value.dval);
RETURN_TRUE;
}
@@ -2400,6 +2428,7 @@
int id, type;
#if HAVE_PDFLIB2
int pdf_image;
+ MY_PDF_IMAGE *my_pdf_image;
#else
PDF_image *pdf_image;
#endif
@@ -2427,8 +2456,9 @@
convert_to_long(arg2);
id=arg2->value.lval;
#if HAVE_PDFLIB2
- pdf_image = (int) php3_list_find(id,&type);
- if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
+/* pdf_image = (int) php3_list_find(id,&type);*/
+ my_pdf_image = (MY_PDF_IMAGE *) php3_list_find(id,&type);
+ if(my_pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
#else
pdf_image = php3_list_find(id,&type);
if(!pdf_image || type!=PDF_GLOBAL(le_pdf_image)) {
@@ -2437,7 +2467,7 @@
RETURN_FALSE;
}
- PDF_put_image(pdf, pdf_image);
+ PDF_put_image(pdf, my_pdf_image->image);
RETURN_TRUE;
}
@@ -2450,6 +2480,7 @@
int id, type;
#if HAVE_PDFLIB2
int pdf_image;
+ MY_PDF_IMAGE *my_pdf_image;
#else
PDF_image *pdf_image;
#endif
@@ -2477,8 +2508,9 @@
convert_to_long(arg2);
id=arg2->value.lval;
#if HAVE_PDFLIB2
- pdf_image = (int) php3_list_find(id,&type);
- if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
+/* pdf_image = (int) php3_list_find(id,&type); */
+ my_pdf_image = (MY_PDF_IMAGE *) php3_list_find(id,&type);
+ if(my_pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
#else
pdf_image = php3_list_find(id,&type);
if(!pdf_image || type!=PDF_GLOBAL(le_pdf_image)) {
@@ -2491,7 +2523,7 @@
convert_to_double(arg4);
convert_to_double(arg5);
- PDF_execute_image(pdf, pdf_image, (float) arg3->value.dval, (float) arg4->value.dval,
arg5->value.dval);
+ PDF_execute_image(pdf, my_pdf_image->image, (float) arg3->value.dval, (float)
arg4->value.dval, arg5->value.dval);
RETURN_TRUE;
}
@@ -2505,6 +2537,7 @@
int id, type;
int width;
int pdf_image;
+ MY_PDF_IMAGE *my_pdf_image;
PDF *pdf;
PDF_TLS_VARS;
@@ -2522,13 +2555,14 @@
convert_to_long(arg2);
id=arg2->value.lval;
- pdf_image = (int) php3_list_find(id,&type);
- if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
+/* pdf_image = (int) php3_list_find(id,&type);*/
+ my_pdf_image = (MY_PDF_IMAGE *) php3_list_find(id,&type);
+ if(my_pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
php3_error(E_WARNING,"Unable to find identifier %d",id);
RETURN_FALSE;
}
- width = PDF_get_image_width(pdf, pdf_image);
+ width = PDF_get_image_width(pdf, my_pdf_image->image);
RETURN_LONG(width);
}
@@ -2541,6 +2575,7 @@
int id, type;
int height;
int pdf_image;
+ MY_PDF_IMAGE *my_pdf_image;
PDF *pdf;
PDF_TLS_VARS;
@@ -2558,13 +2593,14 @@
convert_to_long(arg2);
id=arg2->value.lval;
- pdf_image = (int) php3_list_find(id,&type);
- if(pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
+/* pdf_image = (int) php3_list_find(id,&type);*/
+ my_pdf_image = (MY_PDF_IMAGE *) php3_list_find(id,&type);
+ if(my_pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) {
php3_error(E_WARNING,"Unable to find identifier %d",id);
RETURN_FALSE;
}
- height = PDF_get_image_height(pdf, pdf_image);
+ height = PDF_get_image_height(pdf, my_pdf_image->image);
RETURN_LONG(height);
}