[pecl-text-xdiff] main: Merge pull request #9 from ranvis/fix-error-leak

From: Date: Sun, 05 Apr 2026 17:07:48 +0000
Subject: [pecl-text-xdiff] main: Merge pull request #9 from ranvis/fix-error-leak
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-28480@lists.php.net to get a copy of this message
Author: Rasmus Lerdorf (rlerdorf) Committer: GitHub (web-flow) Pusher: rlerdorf Date: 2026-04-05T18:07:40+01:00 Commit: https://github.com/php/pecl-text-xdiff/commit/d785b595426c1cd632608409c39da196cb7097d7 Raw diff: https://github.com/php/pecl-text-xdiff/commit/d785b595426c1cd632608409c39da196cb7097d7.diff Merge pull request #9 from ranvis/fix-error-leak Fix memory leak when $error on input is refcounted. Changed paths: M xdiff.c Diff: diff --git a/xdiff.c b/xdiff.c index 778ab22..9b0f8c3 100644 --- a/xdiff.c +++ b/xdiff.c @@ -57,6 +57,15 @@ # pragma pack(pop) #endif +#ifndef ZEND_TRY_ASSIGN_REF_STRINGL +#define ZEND_TRY_ASSIGN_REF_STRINGL(zv, s, l) do { \ + zval *_zv = (zv); \ + ZVAL_DEREF(_zv); \ + zval_ptr_dtor(_zv); \ + ZVAL_STRINGL(_zv, (s), (l)); \ +} while (0) +#endif + /* Not exported by header file */ extern char libxdiff_version[]; @@ -505,8 +514,7 @@ PHP_FUNCTION(xdiff_string_patch) goto out_free_error_string; if (error_string.size > 0 && error_ref) { - ZVAL_DEREF(error_ref); - ZVAL_STRINGL(error_ref, error_string.ptr, error_string.size); + ZEND_TRY_ASSIGN_REF_STRINGL(error_ref, error_string.ptr, error_string.size); } if (output_string.size > 0) { @@ -676,8 +684,7 @@ PHP_FUNCTION(xdiff_string_merge3) goto out_free_error_string; if (error_string.size > 0 && error_ref) { - ZVAL_DEREF(error_ref); - ZVAL_STRINGL(error_ref, error_string.ptr, error_string.size); + ZEND_TRY_ASSIGN_REF_STRINGL(error_ref, error_string.ptr, error_string.size); } if (output_string.size > 0) {

« previous php.pecl.cvs (#28480) next »