@@ -218,6 +218,10 @@ static int php_curl_stream_close(php_stream *stream, int close_handle TSRMLS_DC)
218
218
curl_easy_cleanup (curlstream -> curl );
219
219
curl_multi_cleanup (curlstream -> multi );
220
220
221
+ if (curlstream -> headers_slist ) {
222
+ curl_slist_free_all (curlstream -> headers_slist );
223
+ }
224
+
221
225
/* we are not closing curlstream->readbuf here, because we export
222
226
* it as a zval with the wrapperdata - the engine will garbage collect it */
223
227
@@ -268,7 +272,6 @@ php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename,
268
272
php_stream * stream ;
269
273
php_curl_stream * curlstream ;
270
274
zval * tmp , * * ctx_opt = NULL ;
271
- struct curl_slist * slist = NULL ;
272
275
273
276
curlstream = emalloc (sizeof (php_curl_stream ));
274
277
memset (curlstream , 0 , sizeof (php_curl_stream ));
@@ -279,6 +282,7 @@ php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename,
279
282
curlstream -> curl = curl_easy_init ();
280
283
curlstream -> multi = curl_multi_init ();
281
284
curlstream -> pending = 1 ;
285
+ curlstream -> headers_slist = NULL ;
282
286
283
287
/* if opening for an include statement, ensure that the local storage will
284
288
* have a FILE* associated with it.
@@ -351,7 +355,7 @@ php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename,
351
355
zend_hash_move_forward_ex (Z_ARRVAL_PP (ctx_opt ), & pos )
352
356
) {
353
357
if (Z_TYPE_PP (header ) == IS_STRING ) {
354
- slist = curl_slist_append (slist , Z_STRVAL_PP (header ));
358
+ curlstream -> headers_slist = curl_slist_append (curlstream -> headers_slist , Z_STRVAL_PP (header ));
355
359
}
356
360
}
357
361
} else if (Z_TYPE_PP (ctx_opt ) == IS_STRING && Z_STRLEN_PP (ctx_opt )) {
@@ -361,14 +365,14 @@ php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename,
361
365
p = php_strtok_r (copy_ctx_opt , "\r\n" , & token );
362
366
while (p ) {
363
367
trimmed = php_trim (p , strlen (p ), NULL , 0 , NULL , 3 TSRMLS_CC );
364
- slist = curl_slist_append (slist , trimmed );
368
+ curlstream -> headers_slist = curl_slist_append (curlstream -> headers_slist , trimmed );
365
369
efree (trimmed );
366
370
p = php_strtok_r (NULL , "\r\n" , & token );
367
371
}
368
372
efree (copy_ctx_opt );
369
373
}
370
- if (slist ) {
371
- curl_easy_setopt (curlstream -> curl , CURLOPT_HTTPHEADER , slist );
374
+ if (curlstream -> headers_slist ) {
375
+ curl_easy_setopt (curlstream -> curl , CURLOPT_HTTPHEADER , curlstream -> headers_slist );
372
376
}
373
377
}
374
378
if (SUCCESS == php_stream_context_get_option (context , "http" , "method" , & ctx_opt ) && Z_TYPE_PP (ctx_opt ) == IS_STRING ) {
@@ -500,18 +504,10 @@ php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename,
500
504
}
501
505
}
502
506
503
- /* context headers are not needed anymore */
504
- if (slist ) {
505
- curl_easy_setopt (curlstream -> curl , CURLOPT_HTTPHEADER , NULL );
506
- curl_slist_free_all (slist );
507
- }
508
507
return stream ;
509
508
510
509
exit_fail :
511
510
php_stream_close (stream );
512
- if (slist ) {
513
- curl_slist_free_all (slist );
514
- }
515
511
return NULL ;
516
512
}
517
513
0 commit comments