@@ -4071,6 +4071,7 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
40714071 dest = VCWD_FOPEN (fn_dest , "wb" );
40724072 if (!dest ) {
40734073 php_error_docref (NULL , E_WARNING , "Unable to open '%s' for writing" , fn_dest );
4074+ fclose (org );
40744075 RETURN_FALSE ;
40754076 }
40764077
@@ -4079,6 +4080,8 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
40794080 im_org = gdImageCreateFromGif (org );
40804081 if (im_org == NULL ) {
40814082 php_error_docref (NULL , E_WARNING , "Unable to open '%s' Not a valid GIF file" , fn_dest );
4083+ fclose (org );
4084+ fclose (dest );
40824085 RETURN_FALSE ;
40834086 }
40844087 break ;
@@ -4089,6 +4092,8 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
40894092 im_org = gdImageCreateFromJpegEx (org , ignore_warning );
40904093 if (im_org == NULL ) {
40914094 php_error_docref (NULL , E_WARNING , "Unable to open '%s' Not a valid JPEG file" , fn_dest );
4095+ fclose (org );
4096+ fclose (dest );
40924097 RETURN_FALSE ;
40934098 }
40944099 break ;
@@ -4099,17 +4104,23 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
40994104 im_org = gdImageCreateFromPng (org );
41004105 if (im_org == NULL ) {
41014106 php_error_docref (NULL , E_WARNING , "Unable to open '%s' Not a valid PNG file" , fn_dest );
4107+ fclose (org );
4108+ fclose (dest );
41024109 RETURN_FALSE ;
41034110 }
41044111 break ;
41054112#endif /* HAVE_GD_PNG */
41064113
41074114 default :
41084115 php_error_docref (NULL , E_WARNING , "Format not supported" );
4116+ fclose (org );
4117+ fclose (dest );
41094118 RETURN_FALSE ;
41104119 break ;
41114120 }
41124121
4122+ fclose (org );
4123+
41134124 org_width = gdImageSX (im_org );
41144125 org_height = gdImageSY (im_org );
41154126
@@ -4140,30 +4151,38 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
41404151 im_tmp = gdImageCreate (dest_width , dest_height );
41414152 if (im_tmp == NULL ) {
41424153 php_error_docref (NULL , E_WARNING , "Unable to allocate temporary buffer" );
4154+ fclose (dest );
4155+ gdImageDestroy (im_org );
41434156 RETURN_FALSE ;
41444157 }
41454158
41464159 gdImageCopyResized (im_tmp , im_org , 0 , 0 , 0 , 0 , dest_width , dest_height , org_width , org_height );
41474160
41484161 gdImageDestroy (im_org );
41494162
4150- fclose (org );
4151-
41524163 im_dest = gdImageCreate (dest_width , dest_height );
41534164 if (im_dest == NULL ) {
41544165 php_error_docref (NULL , E_WARNING , "Unable to allocate destination buffer" );
4166+ fclose (dest );
4167+ gdImageDestroy (im_tmp );
41554168 RETURN_FALSE ;
41564169 }
41574170
41584171 white = gdImageColorAllocate (im_dest , 255 , 255 , 255 );
41594172 if (white == -1 ) {
41604173 php_error_docref (NULL , E_WARNING , "Unable to allocate the colors for the destination buffer" );
4174+ fclose (dest );
4175+ gdImageDestroy (im_tmp );
4176+ gdImageDestroy (im_dest );
41614177 RETURN_FALSE ;
41624178 }
41634179
41644180 black = gdImageColorAllocate (im_dest , 0 , 0 , 0 );
41654181 if (black == -1 ) {
41664182 php_error_docref (NULL , E_WARNING , "Unable to allocate the colors for the destination buffer" );
4183+ fclose (dest );
4184+ gdImageDestroy (im_tmp );
4185+ gdImageDestroy (im_dest );
41674186 RETURN_FALSE ;
41684187 }
41694188
0 commit comments