Re: com php-src: Fixed bug memleak in header_register_callback: NEWS main/SAPI.c main/SAPI.h tests/basic/header_register_callback.phpt
| From: | Xinchen Hui | Date: | Sun, 13 Dec 2015 15:53:21 +0000 |
| Subject: | Re: com php-src: Fixed bug memleak in header_register_callback: NEWS main/SAPI.c main/SAPI.h tests/basic/header_register_callback.phpt | ||
| References: | 1 2 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-90252@lists.php.net to get a copy of this message | ||
Hey:
On Sun, Dec 13, 2015 at 8:37 PM, Anatol Belski <anatol.php@belski.net>
wrote:
> Hi Hui,
>
> > -----Original Message-----
> > From: Xinchen Hui [mailto:laruence@php.net]
> > Sent: Friday, December 11, 2015 10:27 AM
> > To: php-cvs@lists.php.net
> > Subject: [PHP-CVS] com php-src: Fixed bug memleak in
> > header_register_callback: NEWS main/SAPI.c main/SAPI.h
> > tests/basic/header_register_callback.phpt
> >
> > Commit: b5adfee320de8d8aa13ee9d97f040f4d416f40d5
> > Author: Xinchen Hui <laruence@gmail.com> Fri, 11 Dec 2015
> 17:26:31
> > +0800
> > Parents: 5c5209d676fd9eaef861792d03ff819ed36e7ea5
> > Branches: PHP-7.0 master
> >
> > Link: http://git.php.net/?p=php-
> > src.git;a=commitdiff;h=b5adfee320de8d8aa13ee9d97f040f4d416f40d5
> >
> > Log:
> > Fixed bug memleak in header_register_callback
> >
> > Changed paths:
> > M NEWS
> > M main/SAPI.c
> > M main/SAPI.h
> > A tests/basic/header_register_callback.phpt
> >
> >
> > Diff:
> > diff --git a/NEWS b/NEWS
> > index 8f3d442..ed32b6c 100644
> > --- a/NEWS
> > +++ b/NEWS
> > @@ -3,6 +3,7 @@ PHP
> NEWS
> > ?? Jan 2016 PHP 7.0.2
> >
> > - Core:
> > + . Fixed bug memleak in header_register_callback. (Laruence)
> > . Fixed bug #71067 (Local object in class method stays in memory for
> each
> > call). (Laruence)
> > . Fixed bug #66909 (configure fails utf8_to_mutf7 test). (Michael
> Orlitzky) diff -
> > -git a/main/SAPI.c b/main/SAPI.c index c0ea144..9d189f6 100644
> > --- a/main/SAPI.c
> > +++ b/main/SAPI.c
> > @@ -142,14 +142,14 @@ PHP_FUNCTION(header_register_callback)
> > }
> > /* }}} */
> >
> > -static void sapi_run_header_callback(void)
> > +static void sapi_run_header_callback(zval *callback)
> > {
> > int error;
> > zend_fcall_info fci;
> > char *callback_error = NULL;
> > zval retval;
> >
> > - if (zend_fcall_info_init(&SG(callback_func), 0, &fci,
> &SG(fci_cache),
> > NULL, &callback_error) == SUCCESS) {
> > + if (zend_fcall_info_init(callback, 0, &fci, &SG(fci_cache), NULL,
> > +&callback_error) == SUCCESS) {
> > fci.retval = &retval;
> >
> > error = zend_call_function(&fci, &SG(fci_cache)); @@ -446,7
> > +446,6 @@ SAPI_API void sapi_activate(void)
> > SG(sapi_headers).http_status_line = NULL;
> > SG(sapi_headers).mimetype = NULL;
> > SG(headers_sent) = 0;
> > - SG(callback_run) = 0;
> > ZVAL_UNDEF(&SG(callback_func));
> > SG(read_post_bytes) = 0;
> > SG(request_info).request_body = NULL;
> > @@ -543,8 +542,6 @@ SAPI_API void sapi_deactivate(void)
> > sapi_send_headers_free();
> > SG(sapi_started) = 0;
> > SG(headers_sent) = 0;
> > - SG(callback_run) = 0;
> > - zval_ptr_dtor(&SG(callback_func));
> > SG(request_info).headers_read = 0;
> > SG(global_request_time) = 0;
> > }
> > @@ -851,7 +848,7 @@ SAPI_API int sapi_send_headers(void)
> > int retval;
> > int ret = FAILURE;
> >
> > - if (SG(headers_sent) || SG(request_info).no_headers ||
> > SG(callback_run)) {
> > + if (SG(headers_sent) || SG(request_info).no_headers) {
> > return SUCCESS;
> > }
> >
> > @@ -871,9 +868,12 @@ SAPI_API int sapi_send_headers(void)
> > SG(sapi_headers).send_default_content_type = 0;
> > }
> >
> > - if (Z_TYPE(SG(callback_func)) != IS_UNDEF && !SG(callback_run)) {
> > - SG(callback_run) = 1;
> > - sapi_run_header_callback();
> > + if (Z_TYPE(SG(callback_func)) != IS_UNDEF) {
> > + zval cb;
> > + ZVAL_COPY_VALUE(&cb, &SG(callback_func));
> > + ZVAL_UNDEF(&SG(callback_func));
> > + sapi_run_header_callback(&cb);
> > + zval_ptr_dtor(&cb);
> > }
> >
> > SG(headers_sent) = 1;
> > diff --git a/main/SAPI.h b/main/SAPI.h
> > index 67ee50d..7a80e70 100644
> > --- a/main/SAPI.h
> > +++ b/main/SAPI.h
> > @@ -136,7 +136,6 @@ typedef struct _sapi_globals_struct {
> > HashTable known_post_content_types;
> > zval callback_func;
> > zend_fcall_info_cache fci_cache;
> > - zend_bool callback_run;
> > } sapi_globals_struct;
> >
> I'd suggest to leave that SG struct member as dummy in 7.0. Even it's not
> needed after this patch, ABI should be kept.
>
I think it's okey
It's the last element in that struct, which means the ABI should not be
broken
thanks
>
> Regards
>
> Anatol
>
> >
> > diff --git a/tests/basic/header_register_callback.phpt
> > b/tests/basic/header_register_callback.phpt
> > new file mode 100644
> > index 0000000..641ee9e
> > --- /dev/null
> > +++ b/tests/basic/header_register_callback.phpt
> > @@ -0,0 +1,8 @@
> > +--TEST--
> > +Test header_register_callback
> > +--FILE--
> > +<?php
> > +header_register_callback(function() { echo "sent";}); ?>
> > +--EXPECT--
> > +sent
> >
> >
> > --
> > PHP CVS Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
--
Xinchen Hui
@Laruence
http://www.laruence.com/