Commit 61a190cdd2e for php.net
commit 61a190cdd2e0020cbecf46c4b42525a8dca0cb4c
Author: NickSdot <32384907+NickSdot@users.noreply.github.com>
Date: Thu Jul 30 20:50:14 2026 +0700
Prevents tests from leaking System V IPC objects (#22912)
* Clean up IPC objects in arginfo mismatch test
* Fix GH-16592 test leaking a message queue
diff --git a/Zend/tests/arginfo_zpp_mismatch.phpt b/Zend/tests/arginfo_zpp_mismatch.phpt
index d7aefc6f374..94f6b070900 100644
--- a/Zend/tests/arginfo_zpp_mismatch.phpt
+++ b/Zend/tests/arginfo_zpp_mismatch.phpt
@@ -10,6 +10,36 @@
require __DIR__ . "/arginfo_zpp_mismatch.inc";
+function testWeakSysvIpcFunction($function): bool {
+ if (!in_array($function, ['msg_queue_exists', 'msg_get_queue', 'sem_get', 'shm_attach'], true)) {
+ return false;
+ }
+
+ for ($argumentCount = 0; $argumentCount <= 8; $argumentCount++) {
+ $arguments = array_fill(0, $argumentCount, null);
+ if ($function === 'msg_queue_exists' && $argumentCount >= 1) {
+ $arguments[0] = 1;
+ }
+ if (($function === 'sem_get' || $function === 'shm_attach') && $argumentCount >= 3) {
+ $arguments[2] = 0600;
+ }
+
+ try {
+ $result = @$function(...$arguments);
+ if ($result instanceof SysvMessageQueue) {
+ msg_remove_queue($result);
+ } elseif ($result instanceof SysvSemaphore) {
+ sem_remove($result);
+ } elseif ($result instanceof SysvSharedMemory) {
+ shm_remove($result);
+ }
+ } catch (Throwable) {
+ }
+ }
+
+ return true;
+}
+
function test($function) {
if (skipFunction($function)) {
return;
@@ -21,6 +51,10 @@ function test($function) {
} else {
echo "Testing " . get_class($function[0]) . "::$function[1]\n";
}
+ if (testWeakSysvIpcFunction($function)) {
+ ob_end_clean();
+ return;
+ }
try {
@$function();
} catch (Throwable) {
diff --git a/ext/sysvmsg/tests/gh16592.phpt b/ext/sysvmsg/tests/gh16592.phpt
index 8490d000f89..d48927b4dfe 100644
--- a/ext/sysvmsg/tests/gh16592.phpt
+++ b/ext/sysvmsg/tests/gh16592.phpt
@@ -8,11 +8,14 @@ class Test {
function __serialize() {}
}
-$q = msg_get_queue(1);
+// use a private queue, so we only remove our own.
+$q = msg_get_queue(0, 0600);
try {
msg_send($q, 1, new Test, true);
} catch (\TypeError $e) {
echo $e->getMessage();
+} finally {
+ msg_remove_queue($q);
}
?>
--EXPECT--