fix leak reading partial lobs
authorMichael Wallner <mike@php.net>
Mon, 10 Jan 2022 23:17:30 +0000 (00:17 +0100)
committerMichael Wallner <mike@php.net>
Mon, 10 Jan 2022 23:17:30 +0000 (00:17 +0100)
ion.c
tests/LOB/RW.phpt [new file with mode: 0644]

diff --git a/ion.c b/ion.c
index 8bf7e0a3e11b63a5f2ab0361fb3ee629ee1f2726..fe7a38e4b6f732649434ca153c17a3a19a0cf288 100644 (file)
--- a/ion.c
+++ b/ion.c
@@ -1036,9 +1036,7 @@ static void read_part(INTERNAL_FUNCTION_PARAMETERS, read_part_fn fn)
                RETURN_TRUE;
        }
 fail:
-       if (zstr != Z_STR_P(ref)) {
-               zend_string_release(zstr);
-       }
+       zend_string_release(zstr);
        ZVAL_EMPTY_STRING(ref);
        RETURN_FALSE;
 }
diff --git a/tests/LOB/RW.phpt b/tests/LOB/RW.phpt
new file mode 100644 (file)
index 0000000..fa1a576
--- /dev/null
@@ -0,0 +1,48 @@
+--TEST--
+ion\LOB/RW
+--EXTENSIONS--
+ion
+--FILE--
+TEST
+<?php
+$s = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
+array_map(fn($s)=>stream_set_blocking($s,false), $s);
+
+$w = new ion\Writer\Stream\Writer($s[0]);
+$w->startLob(ion\Type::CLob);
+$w->appendLob(str_repeat("a", 0x1000));
+
+$l = 0;
+$r = new ion\Reader\Stream\Reader($s[1]);
+for ($i = 0; $i < 10; $i++) {
+       $W=$E=[];
+       for ($R=[$s[1]]; stream_select($R, $W, $E, 0); ) {
+               if ($r->getType() != ion\Type::CLob)
+                       $r->next();
+               echo "+";
+               $r->readLobPart($b);
+               $l += strlen($b);
+       }
+       echo "-";
+       $w->appendLob(str_repeat("a", 0x1000));
+}
+
+$w->finishLob();
+$w->finish();
+
+while ($r->readLobPart($b)) {
+       echo ".";
+    $l += strlen($b);
+}
+echo "\n";
+
+$r->next();
+var_dump($r->key(), $l);
+?>
+DONE
+--EXPECTF--
+TEST
+%r[-+]+\.+%r
+enum(ion\Type::EOF)
+int(45056)
+DONE