cvs: /php3/functions pdf.c

From: Date: Tue, 14 Sep 1999 11:26:11 +0000
Subject: cvs: /php3/functions pdf.c
Groups: php.dev 
Request: Send a blank email to php-dev+get-10889@lists.php.net to get a copy of this message
steinm Tue Sep 14 07:26:11 1999 EDT Modified files: /php3/functions pdf.c Log: - undid last change to fix the memory leak, because there is a much easier solution. Must have been blind. Thanks to Thomas Merz for the pointer. Index: php3/functions/pdf.c diff -u php3/functions/pdf.c:1.51 php3/functions/pdf.c:1.52 --- php3/functions/pdf.c:1.51 Tue Sep 14 06:02:16 1999 +++ php3/functions/pdf.c Tue Sep 14 07:26:11 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pdf.c,v 1.51 1999/09/14 10:02:16 steinm Exp $ */ +/* $Id: pdf.c,v 1.52 1999/09/14 11:26:11 steinm Exp $ */ /* pdflib 0.6 is subject to the ALADDIN FREE PUBLIC LICENSE. Copyright (C) 1997 Thomas Merz. */ @@ -58,13 +58,6 @@ #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; @@ -198,16 +191,12 @@ #endif #if HAVE_PDFLIB2 -/*static void _free_pdf_image(int image)*/ -static void _free_pdf_image(MY_PDF_IMAGE *image) +static void _free_pdf_image(int 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. @@ -2163,7 +2152,6 @@ int id, type; #if HAVE_PDFLIB2 int pdf_image; - MY_PDF_IMAGE *my_pdf_image; #else PDF_image *pdf_image; #endif @@ -2190,10 +2178,7 @@ RETURN_FALSE; } - 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)); + id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image)); RETURN_LONG(id); } /* }}} */ @@ -2205,7 +2190,6 @@ int id, type; #if HAVE_PDFLIB2 int pdf_image; - MY_PDF_IMAGE *my_pdf_image; #else PDF_image *pdf_image; #endif @@ -2232,10 +2216,7 @@ RETURN_FALSE; } - 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)); + id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image)); RETURN_LONG(id); } /* }}} */ @@ -2249,7 +2230,6 @@ 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; @@ -2295,16 +2275,14 @@ #else pdf_image = PDF_open_image(pdf, "raw", "memory", buffer, im->sx*im->sy*3, im->sx, im->sy, 3, 8, NULL); #endif + efree(buffer); if(0 > pdf_image) { php3_error(E_WARNING, "Could not open image"); RETURN_FALSE; } - 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)); + id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image)); RETURN_LONG(id); } /* }}} */ @@ -2318,7 +2296,6 @@ int id, type; #if HAVE_PDFLIB2 int pdf_image; - MY_PDF_IMAGE *my_pdf_image; #else PDF_image *pdf_image; #endif @@ -2348,8 +2325,8 @@ convert_to_long(arg2); id=arg2->value.lval; #if HAVE_PDFLIB2 - my_pdf_image = (MY_PDF_IMAGE *) php3_list_find(id,&type); - if(my_pdf_image < 0 || type!=PDF_GLOBAL(le_pdf_image)) { + pdf_image = (int) php3_list_find(id,&type); + if(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)) { @@ -2359,9 +2336,8 @@ } #if HAVE_PDFLIB2 - PDF_close_image(pdf, my_pdf_image->image); + PDF_close_image(pdf, pdf_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); @@ -2378,7 +2354,6 @@ int id, type; #if HAVE_PDFLIB2 int pdf_image; - MY_PDF_IMAGE *my_pdf_image; #else PDF_image *pdf_image; #endif @@ -2400,9 +2375,8 @@ convert_to_long(arg2); id=arg2->value.lval; #if HAVE_PDFLIB2 -/* 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)) { + pdf_image = (int) php3_list_find(id,&type); + if(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)) { @@ -2415,7 +2389,7 @@ convert_to_double(arg4); convert_to_double(arg5); - PDF_place_image(pdf, my_pdf_image->image, (float) arg3->value.dval, (float) arg4->value.dval, arg5->value.dval); + PDF_place_image(pdf, pdf_image, (float) arg3->value.dval, (float) arg4->value.dval, arg5->value.dval); RETURN_TRUE; } @@ -2428,7 +2402,6 @@ int id, type; #if HAVE_PDFLIB2 int pdf_image; - MY_PDF_IMAGE *my_pdf_image; #else PDF_image *pdf_image; #endif @@ -2456,9 +2429,8 @@ convert_to_long(arg2); id=arg2->value.lval; #if HAVE_PDFLIB2 -/* 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)) { + pdf_image = (int) php3_list_find(id,&type); + if(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)) { @@ -2467,7 +2439,7 @@ RETURN_FALSE; } - PDF_put_image(pdf, my_pdf_image->image); + PDF_put_image(pdf, pdf_image); RETURN_TRUE; } @@ -2480,7 +2452,6 @@ int id, type; #if HAVE_PDFLIB2 int pdf_image; - MY_PDF_IMAGE *my_pdf_image; #else PDF_image *pdf_image; #endif @@ -2508,9 +2479,8 @@ convert_to_long(arg2); id=arg2->value.lval; #if HAVE_PDFLIB2 -/* 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)) { + pdf_image = (int) php3_list_find(id,&type); + if(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)) { @@ -2523,7 +2493,7 @@ convert_to_double(arg4); convert_to_double(arg5); - PDF_execute_image(pdf, my_pdf_image->image, (float) arg3->value.dval, (float) arg4->value.dval, arg5->value.dval); + PDF_execute_image(pdf, pdf_image, (float) arg3->value.dval, (float) arg4->value.dval, arg5->value.dval); RETURN_TRUE; } @@ -2537,7 +2507,6 @@ int id, type; int width; int pdf_image; - MY_PDF_IMAGE *my_pdf_image; PDF *pdf; PDF_TLS_VARS; @@ -2555,14 +2524,13 @@ convert_to_long(arg2); id=arg2->value.lval; -/* 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)) { + pdf_image = (int) php3_list_find(id,&type); + if(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, my_pdf_image->image); + width = PDF_get_image_width(pdf, pdf_image); RETURN_LONG(width); } @@ -2575,7 +2543,6 @@ int id, type; int height; int pdf_image; - MY_PDF_IMAGE *my_pdf_image; PDF *pdf; PDF_TLS_VARS; @@ -2593,14 +2560,13 @@ convert_to_long(arg2); id=arg2->value.lval; -/* 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)) { + pdf_image = (int) php3_list_find(id,&type); + if(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, my_pdf_image->image); + height = PDF_get_image_height(pdf, pdf_image); RETURN_LONG(height); }

« previous php.dev (#10889) next »