Skip to content

Commit b41cdea

Browse files
authored
Fix mem error (swoole#4050)
* fix * fix 2 * fix 3 * fix tests * fix tests[2]
1 parent c2eceb4 commit b41cdea

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

ext-src/php_swoole.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ SW_API bool php_swoole_is_enable_coroutine() {
398398
static void fatal_error(int code, const char *format, ...) {
399399
va_list args;
400400
zend_object *exception;
401+
if (sw_reactor()) {
402+
sw_reactor()->bailout = true;
403+
}
401404
va_start(args, format);
402405
exception = zend_throw_exception(swoole_error_ce, swoole::std_string::vformat(format, args).c_str(), code);
403406
va_end(args);

ext-src/swoole_runtime.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ static php_stream *socket_create(const char *proto,
10691069
zval *ztmp;
10701070
if (php_swoole_array_get_value_ex(options, name, ztmp)) {
10711071
add_assoc_zval_ex(&zalias, alias, strlen(alias), ztmp);
1072+
zval_add_ref(ztmp);
10721073
}
10731074
};
10741075

@@ -1087,7 +1088,7 @@ static php_stream *socket_create(const char *proto,
10871088
if (!sock->ssl_check_context()) {
10881089
goto _failed;
10891090
}
1090-
zend_array_destroy(Z_ARRVAL(zalias));
1091+
zval_dtor(&zalias);
10911092
}
10921093
#endif
10931094
}

tests/swoole_client_sync/sendto.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ $pm = new SwooleTest\ProcessManager;
1515
$pm->parentFunc = function () use ($pm) {
1616
$cli = new Client(SWOOLE_SOCK_UDP);
1717

18-
$cli->sendto('127.0.0.1', $pm->getFreePort(), "hello");
19-
$cli->sendto('localhost', $pm->getFreePort(), "hello");
18+
$cli->sendto('127.0.0.1', $pm->getFreePort(), "packet-1");
19+
$cli->sendto('localhost', $pm->getFreePort(), "packet-2");
2020
Assert::false($cli->sendto('error_domain', $pm->getFreePort(), "hello"));
2121
Assert::assert($cli->errCode, SWOOLE_ERROR_DNSLOOKUP_RESOLVE_FAILED);
22-
$cli->sendto('localhost', $pm->getFreePort(), "hello");
22+
$cli->sendto('localhost', $pm->getFreePort(), "packet-3");
2323
echo "DONE\n";
2424
};
2525
$pm->childFunc = function () use ($pm) {
@@ -29,11 +29,11 @@ $pm->childFunc = function () use ($pm) {
2929
$pm->wakeup();
3030
$peer = null;
3131
$ret = $socket->recvfrom($peer);
32-
Assert::eq($ret, 'hello', 'packet-1');
32+
Assert::eq($ret, 'packet-1');
3333
$ret = $socket->recvfrom($peer);
34-
Assert::eq($ret, 'hello', 'packet-2');
34+
Assert::eq($ret, 'packet-2');
3535
$ret = $socket->recvfrom($peer);
36-
Assert::eq($ret, 'hello', 'packet-3');
36+
Assert::eq($ret, 'packet-3');
3737
});
3838
};
3939
$pm->childFirst();

tests/swoole_coroutine/check.phpt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ swoole_coroutine: check if is in the coroutine
55
--FILE--
66
<?php
77
require __DIR__ . '/../include/bootstrap.php';
8+
9+
define('RUN_IN_CHILD', true);
10+
811
$map = [
912
function () {
1013
Co::sleep(0.001);
@@ -54,9 +57,9 @@ $map = [
5457
Co::getaddrinfo('www.swoole.com');
5558
Assert::assert(0); // never here
5659
},
57-
// function () {
58-
// Co::statvfs(__DIR__); // can use outside the coroutine
59-
// },
60+
// function () {
61+
// Co::statvfs(__DIR__);
62+
// },
6063
function () {
6164
Co::exec('echo');
6265
Assert::assert(0); // never here
@@ -112,6 +115,10 @@ if (class_exists(Co\Http2\Client::class)) {
112115
$info_list = [];
113116
foreach ($map as $i => $f) {
114117
$GLOBALS['f'] = $f;
118+
if (RUN_IN_CHILD == false) {
119+
$f();
120+
continue;
121+
}
115122
$process = new Swoole\Process(function () {
116123
function a()
117124
{

0 commit comments

Comments
 (0)