Skip to content

Commit 41dfb72

Browse files
Fix memory leak with OCI_RETURN_LOBS fetch flag (#32)
Co-authored-by: SakiTakamachi <[email protected]>
1 parent 39ff74b commit 41dfb72

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

oci8.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,8 @@ void php_oci_column_hash_dtor(zval *data)
573573
zend_list_close(column->stmtid);
574574
}
575575

576-
if (column->descid) {
577-
if (GC_REFCOUNT(column->descid) == 1)
578-
zend_list_close(column->descid);
579-
else {
580-
GC_DELREF(column->descid);
581-
}
576+
if (column->descid && !GC_DELREF(column->descid)) {
577+
zend_list_free(column->descid);
582578
}
583579

584580
if (column->data) {

tests/gh-4-return-lob.phpt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Bug GH-4 (Memory leak with long query/CLOB) with OCI_RETURN_LOBS
3+
--EXTENSIONS--
4+
oci8
5+
--SKIPIF--
6+
<?php
7+
require_once 'skipifconnectfailure.inc';
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require __DIR__.'/connect.inc';
13+
14+
$expectedStr = str_repeat('a', 1_001);
15+
$sql = 'select concat(TO_CLOB(\'' . str_repeat('a', 1_000) . '\'), TO_CLOB(\'a\')) AS "v" from "DUAL"';
16+
17+
$memUsages = array_flip(range(0, 100 - 1));
18+
foreach (array_keys($memUsages) as $k) {
19+
$stid = oci_parse($c, $sql);
20+
oci_execute($stid);
21+
$row = oci_fetch_array($stid, \OCI_ASSOC | \OCI_RETURN_LOBS);
22+
$res = $row['v'];
23+
if ($res !== $expectedStr) {
24+
var_dump([$expectedStr, $res]);
25+
throw new \Exception('unexpected result');
26+
}
27+
28+
$memUsages[$k] = memory_get_usage();
29+
}
30+
31+
$memUsages = array_slice($memUsages, 1, null, true);
32+
$memUsages = array_unique($memUsages);
33+
34+
if (count($memUsages) !== 1) {
35+
var_dump($memUsages);
36+
throw new \Exception('memory leak detected');
37+
}
38+
39+
echo "ok\n";
40+
41+
?>
42+
--EXPECTF--
43+
ok

0 commit comments

Comments
 (0)