PHP  
 PHP_HEAD
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

Valgrind Report for ext/oci8/tests/bug43497.phpt ('Bug #43497 (OCI8 XML/getClobVal aka temporary LOBs leak UGA memory)')

Script

1: <?php
2:
3:
require dirname(__FILE__).'/connect.inc';
4:
5: function 
sessionid($c)  // determines and returns current session ID
6:
{
7:     
$query "select sid from v\$session where audsid = userenv('sessionid')";
8:
9:     
$stmt oci_parse($c$query);
10:
11:     if (
oci_execute($stmtOCI_DEFAULT)) {
12:         
$row oci_fetch($stmt);
13:         return 
oci_result($stmt1);
14:     }
15:
16:     return 
null;
17: }
18:
19:
20: function 
templobs($c$sid)  // returns number of temporary LOBs
21:
{
22:     
$query "select abstract_lobs from v\$temporary_lobs where sid = " $sid;
23:
24:     
$stmt oci_parse($c$query);
25:
26:     if (
oci_execute($stmtOCI_DEFAULT)) {
27:         
$row oci_fetch($stmt);
28:         
$val oci_result($stmt1);
29:         
oci_free_statement($stmt);
30:         return 
$val;
31:     }
32:     return 
null;
33: }
34:
35:
36:
// Read all XML data using explicit LOB locator
37:
function readxmltab_ex($c)
38: {
39:     
$stmt oci_parse($c"select extract(xml, '/').getclobval() from bug43497_tab");
40:
41:     
$cntchk 0;
42:     if (
oci_execute($stmt)) {
43:         while (
$result oci_fetch_array($stmtOCI_NUM)) {
44:             
$result[0]->free();   // cleanup properly
45:             
++$cntchk;
46:         }
47:     }
48:     echo 
"Loop count check = $cntchk\n";
49: }
50:
51:
// Read all XML data using explicit LOB locator but without freeing the temp lobs
52:
function readxmltab_ex_nofree($c)
53: {
54:     
$stmt oci_parse($c"select extract(xml, '/').getclobval() from bug43497_tab");
55:
56:     
$cntchk 0;
57:     if (
oci_execute($stmt)) {
58:         while (
$result oci_fetch_array($stmtOCI_NUM)) {
59:             ++
$cntchk;
60:         }
61:     }
62:     echo 
"Loop count check = $cntchk\n";
63: }
64:
65:
// Read all XML data using implicit LOB locator
66:
function readxmltab_im($c)
67: {
68:     
$stmt oci_parse($c"select extract(xml, '/').getclobval() from bug43497_tab");
69:
70:     
$cntchk 0;
71:     if (
oci_execute($stmt)) {
72:         while (
$result oci_fetch_array($stmtOCI_NUM+OCI_RETURN_LOBS)) {
73:             ++
$cntchk;
74:         }
75:     }
76:     echo 
"Loop count check = $cntchk\n";
77: }
78:
79: function 
createxmltab($c)  // create table w/ field of XML type
80:
{
81:     @
dropxmltab($c);
82:     
$stmt oci_parse($c"create table bug43497_tab (id number primary key, xml xmltype)");
83:     
oci_execute($stmt);
84: }
85:
86: function 
dropxmltab($c)  // delete table
87:
{
88:     
$stmt oci_parse($c"drop table bug43497_tab");
89:     
oci_execute($stmt);
90: }
91:
92:
93: function 
fillxmltab($c)
94: {
95:     for (
$id 1$id <= 100$id++) {
96:         
97:         
// create an XML element string with random data        
98:         
$s "<data>";
99:         for (
$j 0$j 128$j++) {
100:             
$s .= rand();        
101:         }
102:         
$s .= "</data>\n";        
103:         for (
$j 0$j 4$j++) {
104:             
$s .= $s;
105:         }        
106:         
$data "<?xml version=\"1.0\"?><records>" $s "</records>";
107:         
108:         
// insert XML data into database
109:         
110:         
$stmt oci_parse($c"insert into bug43497_tab(id, xml) values (:id, sys.xmltype.createxml(:xml))");
111:         
oci_bind_by_name($stmt":id"$id);
112:         
$clob oci_new_descriptor($cOCI_D_LOB);
113:         
oci_bind_by_name($stmt":xml"$clob, -1OCI_B_CLOB);
114:         
$clob->writetemporary($data);
115:         
oci_execute($stmt);
116:         
117:         
$clob->close();
118:         
$clob->free();
119:     }
120: }
121:
122:
123:
// Initialize
124:
125:
createxmltab($c);
126:
fillxmltab($c);
127:
128:
// Run Test
129:
130:
$sid sessionid($c);
131:
132: echo 
"Explicit LOB use\n";
133: for (
$i 1$i <= 10$i++) {
134:     echo 
"\nRun              = " $i "\n";
135:     echo 
"Temporary LOBs   = " templobs($c$sid) . "\n";
136:     
readxmltab_ex($c);
137: }
138:
139: echo 
"\nImplicit LOB use\n";
140: for (
$i 1$i <= 10$i++) {
141:     echo 
"\nRun              = " $i "\n";
142:     echo 
"Temporary LOBs   = " templobs($c$sid) . "\n";
143:     
readxmltab_im($c);
144: }
145:
146: echo 
"\nExplicit LOB with no free\n";
147: for (
$i 1$i <= 10$i++) {
148:     echo 
"\nRun              = " $i "\n";
149:     echo 
"Temporary LOBs   = " templobs($c$sid) . "\n";
150:     
readxmltab_ex_nofree($c);
151: }
152:
153:
154:
155:
// Cleanup
156:
157:
dropxmltab($c);
158:
159:
oci_close($c);
160:
161: echo 
"Done\n";
162:
?>
163:

Report

==25058== Invalid read of size 1
==25058==    at 0xA96B1E: zval_get_type (zend_types.h:390)
==25058==    by 0xA96B1E: php_oci_register_taf_callback (oci8_failover.c:108)
==25058==    by 0xA96AD7: php_oci_unregister_taf_callback (oci8_failover.c:92)
==25058==    by 0xA91959: zif_oci_close (oci8_interface.c:1620)
==25058==    by 0x11BD4EB: ZEND_DO_ICALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:573)
==25058==    by 0x1339863: execute_ex (zend_vm_execute.h:59726)
==25058==    by 0x1339EDB: zend_execute (zend_vm_execute.h:63763)
==25058==    by 0x10DF02D: zend_execute_scripts (zend.c:1494)
==25058==    by 0xFD0CE5: php_execute_script (main.c:2566)
==25058==    by 0x133FA79: do_cli (php_cli.c:1011)
==25058==    by 0x134142D: main (php_cli.c:1404)
==25058==  Address 0x14fc8af8 is 136 bytes inside a block of size 144 free'd
==25058==    at 0x4C28BD4: free (vg_replace_malloc.c:529)
==25058==    by 0x1076214: _efree (zend_alloc.c:2428)
==25058==    by 0xA6B758: php_oci_connection_close (oci8.c:2267)
==25058==    by 0xA6517B: php_oci_connection_list_dtor (oci8.c:1266)
==25058==    by 0x1120A31: zend_resource_dtor (zend_list.c:76)
==25058==    by 0x1120B09: zend_list_close (zend_list.c:89)
==25058==    by 0xA9193B: zif_oci_close (oci8_interface.c:1617)
==25058==    by 0x11BD4EB: ZEND_DO_ICALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:573)
==25058==    by 0x1339863: execute_ex (zend_vm_execute.h:59726)
==25058==    by 0x1339EDB: zend_execute (zend_vm_execute.h:63763)
==25058==    by 0x10DF02D: zend_execute_scripts (zend.c:1494)
==25058==    by 0xFD0CE5: php_execute_script (main.c:2566)
==25058==  Block was alloc'd at
==25058==    at 0x4C291FA: malloc (vg_replace_malloc.c:298)
==25058==    by 0x10777DB: __zend_malloc (zend_alloc.c:2811)
==25058==    by 0x1075EF1: _emalloc (zend_alloc.c:2413)
==25058==    by 0x107677F: _safe_emalloc (zend_alloc.c:2472)
==25058==    by 0x1076B91: _ecalloc (zend_alloc.c:2495)
==25058==    by 0xA69EF6: php_oci_do_connect_ex (oci8.c:1981)
==25058==    by 0xA66680: php_oci_do_connect (oci8.c:1645)
==25058==    by 0xA91A11: zif_oci_connect (oci8_interface.c:1640)
==25058==    by 0x11BD9D3: ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER (zend_vm_execute.h:617)
==25058==    by 0x1339863: execute_ex (zend_vm_execute.h:59726)
==25058==    by 0x1339EDB: zend_execute (zend_vm_execute.h:63763)
==25058==    by 0x10DF02D: zend_execute_scripts (zend.c:1494)
==25058== 

 

Generated at Sat, 09 Sep 2017 03:10:54 +0000 (14 days ago)

Copyright © 2005-2017 The PHP Group
All rights reserved.