com php-src: Fix #78762: Failing FFI::cast() may leak memory: NEWS ext/ffi/ffi.c ext/ffi/tests/bug78762.phpt

From: Date: Wed, 30 Oct 2019 16:21:58 +0000
Subject: com php-src: Fix #78762: Failing FFI::cast() may leak memory: NEWS ext/ffi/ffi.c ext/ffi/tests/bug78762.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-109141@lists.php.net to get a copy of this message
Commit: 1e2d3d58a8b392385d926bdca11ba0a0bc2547b4 Author: Christoph M. Becker <cmbecker69@gmx.de> Wed, 30 Oct 2019 17:16:56 +0100 Parents: c76dbefe05d8ef9e0d09205d94a7e3d1fc2b4b80 Branches: PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1e2d3d58a8b392385d926bdca11ba0a0bc2547b4 Log: Fix #78762: Failing FFI::cast() may leak memory We have to release objects when we're done with them. Bugs: https://bugs.php.net/78762 Changed paths: M NEWS M ext/ffi/ffi.c A ext/ffi/tests/bug78762.phpt Diff: diff --git a/NEWS b/NEWS index 889c45f01a5..17dd4756c12 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ PHP NEWS - FFI: . Fixed bug #78716 (Function name mangling is wrong for some parameter types). (cmb) + . Fixed bug #78762 (Failing FFI::cast() may leak memory). (cmb) . Implement FR #78270 (Support __vectorcall convention with FFI). (cmb) - FPM: diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index d231c8a930a..08117cba836 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -3882,6 +3882,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */ cdata->ptr = &cdata->ptr_holder; cdata->ptr_holder = old_cdata->ptr; } else if (type->size > old_type->size) { + zend_object_release(&cdata->std); zend_throw_error(zend_ffi_exception_ce, "attempt to cast to larger type"); return; } else if (ptr != &old_cdata->ptr_holder) { diff --git a/ext/ffi/tests/bug78762.phpt b/ext/ffi/tests/bug78762..phpt new file mode 100644 index 00000000000..5e078bf7c91 --- /dev/null +++ b/ext/ffi/tests/bug78762.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #78762 (Failing FFI::cast() may leak memory) +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +try { + FFI::cast('char[10]', FFI::new('char[1]')); +} catch (FFI\Exception $ex) { + echo $ex->getMessage(), PHP_EOL; +} +?> +--EXPECT-- +attempt to cast to larger type

« previous php.cvs (#109141) next »