Skip to content

Commit d62d292

Browse files
committed
Catch C++ exception when thread creation fails
1 parent 97d91e3 commit d62d292

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ext-src/swoole_thread.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ bool php_swoole_thread_unserialize(zend_string *data, zval *zv) {
250250
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
251251
if (!unserialized) {
252252
swoole_warning("unserialize() failed, Error at offset " ZEND_LONG_FMT " of %zd bytes",
253-
(zend_long)((char *) p - ZSTR_VAL(data)),
253+
(zend_long) ((char *) p - ZSTR_VAL(data)),
254254
l);
255255
} else {
256256
if (ZVAL_IS_ARRAY(zv)) {
@@ -371,7 +371,12 @@ static void php_swoole_thread_create(INTERNAL_FUNCTION_PARAMETERS, zval *zobject
371371
return;
372372
}
373373

374-
to->thread = new std::thread([file, argv]() { php_swoole_thread_start(file, argv); });
374+
try {
375+
to->thread = new std::thread([file, argv]() { php_swoole_thread_start(file, argv); });
376+
} catch (const std::exception &e) {
377+
zend_throw_exception(swoole_exception_ce, e.what(), SW_ERROR_SYSTEM_CALL_FAIL);
378+
return;
379+
}
375380
zend_update_property_long(
376381
swoole_thread_ce, SW_Z8_OBJ_P(zobject), ZEND_STRL("id"), (zend_long) to->thread->native_handle());
377382
}

0 commit comments

Comments
 (0)