Commit 73d9145ef5a for php.net

commit 73d9145ef5a565029ba209047399da8255b35382
Author: ndossche <7771979+ndossche@users.noreply.github.com>
Date:   Sat Jun 6 10:34:49 2026 +0200

    zlib: Fix memory leak in inflate_add()

    Closes GH-22239.

diff --git a/NEWS b/NEWS
index ff552103ebc..e9014b130cd 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,7 @@ PHP                                                                        NEWS
 - Zlib:
   . Fixed memory leak if deflate initialization fails and there is a dict.
     (ndossche)
+  . Fixed memory leak in inflate_add(). (ndossche)

 04 Jun 2026, PHP 8.4.22

diff --git a/ext/zlib/tests/inflate_add_no_dict.phpt b/ext/zlib/tests/inflate_add_no_dict.phpt
new file mode 100644
index 00000000000..da805e56702
--- /dev/null
+++ b/ext/zlib/tests/inflate_add_no_dict.phpt
@@ -0,0 +1,22 @@
+--TEST--
+inflate_add(): Z_NEED_DICT returned when no dictionary provided to inflate_init()
+--EXTENSIONS--
+zlib
+--FILE--
+<?php
+
+$dict = "the quick brown fox jumps over the lazy dog";
+$data = "the quick brown fox";
+
+$dc = deflate_init(ZLIB_ENCODING_DEFLATE, ['dictionary' => $dict]);
+$compressed = deflate_add($dc, $data, ZLIB_FINISH);
+
+// Inflate without supplying the dictionary
+$ic = inflate_init(ZLIB_ENCODING_DEFLATE);
+$result = inflate_add($ic, $compressed, ZLIB_SYNC_FLUSH);
+var_dump($result);
+
+?>
+--EXPECTF--
+Warning: inflate_add(): Inflating this data requires a preset dictionary, please specify it in the options array of inflate_init() in %s on line %d
+bool(false)
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 514e6664b72..a855dbe769f 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -1026,6 +1026,7 @@ PHP_FUNCTION(inflate_add)
 					}
 					break;
 				} else {
+					zend_string_release_ex(out, false);
 					php_error_docref(NULL, E_WARNING, "Inflating this data requires a preset dictionary, please specify it in the options array of inflate_init()");
 					RETURN_FALSE;
 				}