@@ -4071,6 +4071,7 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
4071
4071
dest = VCWD_FOPEN (fn_dest , "wb" );
4072
4072
if (!dest ) {
4073
4073
php_error_docref (NULL , E_WARNING , "Unable to open '%s' for writing" , fn_dest );
4074
+ fclose (org );
4074
4075
RETURN_FALSE ;
4075
4076
}
4076
4077
@@ -4079,6 +4080,8 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
4079
4080
im_org = gdImageCreateFromGif (org );
4080
4081
if (im_org == NULL ) {
4081
4082
php_error_docref (NULL , E_WARNING , "Unable to open '%s' Not a valid GIF file" , fn_dest );
4083
+ fclose (org );
4084
+ fclose (dest );
4082
4085
RETURN_FALSE ;
4083
4086
}
4084
4087
break ;
@@ -4089,6 +4092,8 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
4089
4092
im_org = gdImageCreateFromJpegEx (org , ignore_warning );
4090
4093
if (im_org == NULL ) {
4091
4094
php_error_docref (NULL , E_WARNING , "Unable to open '%s' Not a valid JPEG file" , fn_dest );
4095
+ fclose (org );
4096
+ fclose (dest );
4092
4097
RETURN_FALSE ;
4093
4098
}
4094
4099
break ;
@@ -4099,17 +4104,23 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
4099
4104
im_org = gdImageCreateFromPng (org );
4100
4105
if (im_org == NULL ) {
4101
4106
php_error_docref (NULL , E_WARNING , "Unable to open '%s' Not a valid PNG file" , fn_dest );
4107
+ fclose (org );
4108
+ fclose (dest );
4102
4109
RETURN_FALSE ;
4103
4110
}
4104
4111
break ;
4105
4112
#endif /* HAVE_GD_PNG */
4106
4113
4107
4114
default :
4108
4115
php_error_docref (NULL , E_WARNING , "Format not supported" );
4116
+ fclose (org );
4117
+ fclose (dest );
4109
4118
RETURN_FALSE ;
4110
4119
break ;
4111
4120
}
4112
4121
4122
+ fclose (org );
4123
+
4113
4124
org_width = gdImageSX (im_org );
4114
4125
org_height = gdImageSY (im_org );
4115
4126
@@ -4140,30 +4151,38 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
4140
4151
im_tmp = gdImageCreate (dest_width , dest_height );
4141
4152
if (im_tmp == NULL ) {
4142
4153
php_error_docref (NULL , E_WARNING , "Unable to allocate temporary buffer" );
4154
+ fclose (dest );
4155
+ gdImageDestroy (im_org );
4143
4156
RETURN_FALSE ;
4144
4157
}
4145
4158
4146
4159
gdImageCopyResized (im_tmp , im_org , 0 , 0 , 0 , 0 , dest_width , dest_height , org_width , org_height );
4147
4160
4148
4161
gdImageDestroy (im_org );
4149
4162
4150
- fclose (org );
4151
-
4152
4163
im_dest = gdImageCreate (dest_width , dest_height );
4153
4164
if (im_dest == NULL ) {
4154
4165
php_error_docref (NULL , E_WARNING , "Unable to allocate destination buffer" );
4166
+ fclose (dest );
4167
+ gdImageDestroy (im_tmp );
4155
4168
RETURN_FALSE ;
4156
4169
}
4157
4170
4158
4171
white = gdImageColorAllocate (im_dest , 255 , 255 , 255 );
4159
4172
if (white == -1 ) {
4160
4173
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 );
4161
4177
RETURN_FALSE ;
4162
4178
}
4163
4179
4164
4180
black = gdImageColorAllocate (im_dest , 0 , 0 , 0 );
4165
4181
if (black == -1 ) {
4166
4182
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 );
4167
4186
RETURN_FALSE ;
4168
4187
}
4169
4188
0 commit comments