Skip to content

Commit b5adfee

Browse files
committed
Fixed bug memleak in header_register_callback
1 parent 5c5209d commit b5adfee

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PHP NEWS
33
?? Jan 2016 PHP 7.0.2
44

55
- Core:
6+
. Fixed bug memleak in header_register_callback. (Laruence)
67
. Fixed bug #71067 (Local object in class method stays in memory for each
78
call). (Laruence)
89
. Fixed bug #66909 (configure fails utf8_to_mutf7 test). (Michael Orlitzky)

main/SAPI.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ PHP_FUNCTION(header_register_callback)
142142
}
143143
/* }}} */
144144

145-
static void sapi_run_header_callback(void)
145+
static void sapi_run_header_callback(zval *callback)
146146
{
147147
int error;
148148
zend_fcall_info fci;
149149
char *callback_error = NULL;
150150
zval retval;
151151

152-
if (zend_fcall_info_init(&SG(callback_func), 0, &fci, &SG(fci_cache), NULL, &callback_error) == SUCCESS) {
152+
if (zend_fcall_info_init(callback, 0, &fci, &SG(fci_cache), NULL, &callback_error) == SUCCESS) {
153153
fci.retval = &retval;
154154

155155
error = zend_call_function(&fci, &SG(fci_cache));
@@ -446,7 +446,6 @@ SAPI_API void sapi_activate(void)
446446
SG(sapi_headers).http_status_line = NULL;
447447
SG(sapi_headers).mimetype = NULL;
448448
SG(headers_sent) = 0;
449-
SG(callback_run) = 0;
450449
ZVAL_UNDEF(&SG(callback_func));
451450
SG(read_post_bytes) = 0;
452451
SG(request_info).request_body = NULL;
@@ -543,8 +542,6 @@ SAPI_API void sapi_deactivate(void)
543542
sapi_send_headers_free();
544543
SG(sapi_started) = 0;
545544
SG(headers_sent) = 0;
546-
SG(callback_run) = 0;
547-
zval_ptr_dtor(&SG(callback_func));
548545
SG(request_info).headers_read = 0;
549546
SG(global_request_time) = 0;
550547
}
@@ -851,7 +848,7 @@ SAPI_API int sapi_send_headers(void)
851848
int retval;
852849
int ret = FAILURE;
853850

854-
if (SG(headers_sent) || SG(request_info).no_headers || SG(callback_run)) {
851+
if (SG(headers_sent) || SG(request_info).no_headers) {
855852
return SUCCESS;
856853
}
857854

@@ -871,9 +868,12 @@ SAPI_API int sapi_send_headers(void)
871868
SG(sapi_headers).send_default_content_type = 0;
872869
}
873870

874-
if (Z_TYPE(SG(callback_func)) != IS_UNDEF && !SG(callback_run)) {
875-
SG(callback_run) = 1;
876-
sapi_run_header_callback();
871+
if (Z_TYPE(SG(callback_func)) != IS_UNDEF) {
872+
zval cb;
873+
ZVAL_COPY_VALUE(&cb, &SG(callback_func));
874+
ZVAL_UNDEF(&SG(callback_func));
875+
sapi_run_header_callback(&cb);
876+
zval_ptr_dtor(&cb);
877877
}
878878

879879
SG(headers_sent) = 1;

main/SAPI.h

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ typedef struct _sapi_globals_struct {
136136
HashTable known_post_content_types;
137137
zval callback_func;
138138
zend_fcall_info_cache fci_cache;
139-
zend_bool callback_run;
140139
} sapi_globals_struct;
141140

142141

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Test header_register_callback
3+
--FILE--
4+
<?php
5+
header_register_callback(function() { echo "sent";});
6+
?>
7+
--EXPECT--
8+
sent

0 commit comments

Comments
 (0)