@@ -61,6 +61,16 @@ static int _php_image_stream_putbuf(struct gdIOCtx *ctx, const void* buf, int l)
61
61
}
62
62
63
63
static void _php_image_stream_ctxfree (struct gdIOCtx * ctx )
64
+ {
65
+ if (ctx -> data ) {
66
+ ctx -> data = NULL ;
67
+ }
68
+ if (ctx ) {
69
+ efree (ctx );
70
+ }
71
+ } /* }}} */
72
+
73
+ static void _php_image_stream_ctxfreeandclose (struct gdIOCtx * ctx ) /* {{{ */
64
74
{
65
75
TSRMLS_FETCH ();
66
76
@@ -87,6 +97,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
87
97
gdIOCtx * ctx = NULL ;
88
98
zval * to_zval = NULL ;
89
99
php_stream * stream ;
100
+ int close_stream = 1 ;
90
101
91
102
/* The third (quality) parameter for Wbmp stands for the threshold when called from image2wbmp().
92
103
* The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called
@@ -123,6 +134,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
123
134
if (stream == NULL ) {
124
135
RETURN_FALSE ;
125
136
}
137
+ close_stream = 0 ;
126
138
} else if (Z_TYPE_P (to_zval ) == IS_STRING ) {
127
139
if (CHECK_ZVAL_NULL_PATH (to_zval )) {
128
140
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Invalid 2nd parameter, filename must not contain null bytes" );
@@ -159,7 +171,11 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
159
171
ctx = emalloc (sizeof (gdIOCtx ));
160
172
ctx -> putC = _php_image_stream_putc ;
161
173
ctx -> putBuf = _php_image_stream_putbuf ;
162
- ctx -> gd_free = _php_image_stream_ctxfree ;
174
+ if (close_stream ) {
175
+ ctx -> gd_free = _php_image_stream_ctxfreeandclose ;
176
+ } else {
177
+ ctx -> gd_free = _php_image_stream_ctxfree ;
178
+ }
163
179
ctx -> data = (void * )stream ;
164
180
}
165
181
0 commit comments