@@ -4530,6 +4530,7 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
4530
4530
dest = VCWD_FOPEN (fn_dest , "wb" );
4531
4531
if (!dest ) {
4532
4532
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unable to open '%s' for writing" , fn_dest );
4533
+ fclose (org );
4533
4534
RETURN_FALSE ;
4534
4535
}
4535
4536
@@ -4538,6 +4539,8 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
4538
4539
im_org = gdImageCreateFromGif (org );
4539
4540
if (im_org == NULL ) {
4540
4541
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unable to open '%s' Not a valid GIF file" , fn_dest );
4542
+ fclose (org );
4543
+ fclose (dest );
4541
4544
RETURN_FALSE ;
4542
4545
}
4543
4546
break ;
@@ -4548,6 +4551,8 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
4548
4551
im_org = gdImageCreateFromJpegEx (org , ignore_warning );
4549
4552
if (im_org == NULL ) {
4550
4553
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unable to open '%s' Not a valid JPEG file" , fn_dest );
4554
+ fclose (org );
4555
+ fclose (dest );
4551
4556
RETURN_FALSE ;
4552
4557
}
4553
4558
break ;
@@ -4558,17 +4563,23 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
4558
4563
im_org = gdImageCreateFromPng (org );
4559
4564
if (im_org == NULL ) {
4560
4565
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unable to open '%s' Not a valid PNG file" , fn_dest );
4566
+ fclose (org );
4567
+ fclose (dest );
4561
4568
RETURN_FALSE ;
4562
4569
}
4563
4570
break ;
4564
4571
#endif /* HAVE_GD_PNG */
4565
4572
4566
4573
default :
4567
4574
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Format not supported ");
4575
+ fclose (org );
4576
+ fclose (dest );
4568
4577
RETURN_FALSE ;
4569
4578
break ;
4570
4579
}
4571
4580
4581
+ fclose (org );
4582
+
4572
4583
org_width = gdImageSX (im_org );
4573
4584
org_height = gdImageSY (im_org );
4574
4585
@@ -4599,30 +4610,38 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
4599
4610
im_tmp = gdImageCreate (dest_width , dest_height );
4600
4611
if (im_tmp == NULL ) {
4601
4612
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unable to allocate temporary buffer" );
4613
+ fclose (dest );
4614
+ gdImageDestroy (im_org );
4602
4615
RETURN_FALSE ;
4603
4616
}
4604
4617
4605
4618
gdImageCopyResized (im_tmp , im_org , 0 , 0 , 0 , 0 , dest_width , dest_height , org_width , org_height );
4606
4619
4607
4620
gdImageDestroy (im_org );
4608
4621
4609
- fclose (org );
4610
-
4611
4622
im_dest = gdImageCreate (dest_width , dest_height );
4612
4623
if (im_dest == NULL ) {
4613
4624
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unable to allocate destination buffer" );
4625
+ fclose (dest );
4626
+ gdImageDestroy (im_tmp );
4614
4627
RETURN_FALSE ;
4615
4628
}
4616
4629
4617
4630
white = gdImageColorAllocate (im_dest , 255 , 255 , 255 );
4618
4631
if (white == -1 ) {
4619
4632
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unable to allocate the colors for the destination buffer" );
4633
+ fclose (dest );
4634
+ gdImageDestroy (im_tmp );
4635
+ gdImageDestroy (im_dest );
4620
4636
RETURN_FALSE ;
4621
4637
}
4622
4638
4623
4639
black = gdImageColorAllocate (im_dest , 0 , 0 , 0 );
4624
4640
if (black == -1 ) {
4625
4641
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unable to allocate the colors for the destination buffer" );
4642
+ fclose (dest );
4643
+ gdImageDestroy (im_tmp );
4644
+ gdImageDestroy (im_dest );
4626
4645
RETURN_FALSE ;
4627
4646
}
4628
4647
0 commit comments