Skip to content

Commit 438f692

Browse files
committed
Merge branch 'PHP-8.1'
2 parents e885831 + d052742 commit 438f692

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

Zend/zend.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,9 @@ ZEND_API ZEND_COLD void zend_error_zstr_at(
13471347
EG(num_errors)++;
13481348
EG(errors) = erealloc(EG(errors), sizeof(zend_error_info*) * EG(num_errors));
13491349
EG(errors)[EG(num_errors)-1] = info;
1350+
if (EG(record_errors_without_emitting)) {
1351+
return;
1352+
}
13501353
}
13511354

13521355
/* Report about uncaught exception in case of fatal errors */
@@ -1600,14 +1603,34 @@ ZEND_API ZEND_COLD void zend_error_zstr(int type, zend_string *message) {
16001603
zend_error_zstr_at(type, filename, lineno, message);
16011604
}
16021605

1603-
ZEND_API void zend_begin_record_errors(void)
1606+
static zend_always_inline void zend_begin_record_errors_ex(bool no_emmitting)
16041607
{
16051608
ZEND_ASSERT(!EG(record_errors) && "Error recording already enabled");
16061609
EG(record_errors) = true;
1610+
EG(record_errors_without_emitting) = no_emmitting;
16071611
EG(num_errors) = 0;
16081612
EG(errors) = NULL;
16091613
}
16101614

1615+
ZEND_API void zend_begin_record_errors(void)
1616+
{
1617+
zend_begin_record_errors_ex(false);
1618+
}
1619+
1620+
ZEND_API void zend_begin_record_errors_without_emitting(void)
1621+
{
1622+
zend_begin_record_errors_ex(true);
1623+
}
1624+
1625+
ZEND_API void zend_emit_recorded_errors(void)
1626+
{
1627+
EG(record_errors) = false;
1628+
for (uint32_t i = 0; i < EG(num_errors); i++) {
1629+
zend_error_info *error = EG(errors)[i];
1630+
zend_error_zstr_at(error->type, error->filename, error->lineno, error->message);
1631+
}
1632+
}
1633+
16111634
ZEND_API void zend_free_recorded_errors(void)
16121635
{
16131636
if (!EG(num_errors)) {

Zend/zend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ ZEND_API void zend_save_error_handling(zend_error_handling *current);
398398
ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current);
399399
ZEND_API void zend_restore_error_handling(zend_error_handling *saved);
400400
ZEND_API void zend_begin_record_errors(void);
401+
ZEND_API void zend_begin_record_errors_without_emitting(void);
402+
ZEND_API void zend_emit_recorded_errors(void);
401403
ZEND_API void zend_free_recorded_errors(void);
402404
END_EXTERN_C()
403405

Zend/zend_globals.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,10 @@ struct _zend_executor_globals {
262262
zend_long fiber_stack_size;
263263

264264
/* If record_errors is enabled, all emitted diagnostics will be recorded,
265-
* in addition to being processed as usual. */
265+
* in addition to being processed as usual unless record_errors_without_emitting
266+
* is enabled which supresses processing when the errors are recorded. */
266267
bool record_errors;
268+
bool record_errors_without_emitting;
267269
uint32_t num_errors;
268270
zend_error_info **errors;
269271

ext/opcache/ZendAccelerator.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3931,12 +3931,7 @@ static void preload_link(void)
39313931

39323932
/* Inheritance successful, print out any warnings. */
39333933
zend_error_cb = orig_error_cb;
3934-
EG(record_errors) = false;
3935-
for (uint32_t i = 0; i < EG(num_errors); i++) {
3936-
zend_error_info *error = EG(errors)[i];
3937-
zend_error_zstr_at(
3938-
error->type, error->filename, error->lineno, error->message);
3939-
}
3934+
zend_emit_recorded_errors();
39403935
} zend_catch {
39413936
/* Clear variance obligations that were left behind on bailout. */
39423937
if (CG(delayed_variance_obligations)) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-8409: Error in socket creation when error handler does not clean persistent connection
3+
--FILE--
4+
<?php
5+
set_error_handler(function($errno, $errstring, $errfile, $errline) {
6+
foreach (get_resources() as $res) {
7+
if (get_resource_type($res) === "persistent stream") {
8+
echo "ERROR: persistent stream not closed\n";
9+
}
10+
}
11+
echo "DONE\n";
12+
exit(1);
13+
});
14+
15+
stream_socket_client("tcp://9999.9999.9999.9999:9999", $error_code, $error_message, 0.2, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT);
16+
17+
echo "ERROR: this should not be visible\n";
18+
?>
19+
--EXPECT--
20+
DONE

main/streams/transports.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
131131
(char*)name, namelen, persistent_id, options, flags, timeout,
132132
context STREAMS_REL_CC);
133133

134+
zend_begin_record_errors_without_emitting();
135+
134136
if (stream) {
135137
php_stream_context_set(stream, context);
136138

@@ -181,6 +183,9 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
181183
stream = NULL;
182184
}
183185

186+
zend_emit_recorded_errors();
187+
zend_free_recorded_errors();
188+
184189
return stream;
185190
}
186191

0 commit comments

Comments
 (0)