Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php crashes when freeing oci statement

Status
Not open for further replies.

smeagolgollum

Programmer
Jun 19, 2003
9
FR
Hi
i am having a lot of trouble with one of my scripts
i encapsulated the execution of select statement and their output to the browser in a class.
all it does is connect to the database using user/pass/db given, executes the statement and builds a table from it.

my problem is that when php frees the statement ressource (either with ocifreestatement or when the script finishes)


below is the code that executes the sql statement
when building the table i only use ocifetchinto to retrieve the rows

the really weird thing is that the class works with every other scripts but it won't with that one that uses two instances of the class.


-------------------------------------------------------
Code:
		// pour eviter les plantages de PHP, on fait une copie locale des variables passées à OCI
		$user = $this->ora_user;
		$pass = $this->ora_pass;
		$base = $this->ora_base;
		$bind_vars = $this->bind_vars;
		
		$conn = OCIPLogon($user,$pass,$base);
		if (! $conn) return false;
		$stmt = OCIParse($conn,$sql);
		if (! $stmt) return false;
		foreach($bind_vars as $bind_var => $var)
			if (!OCIBindByName($stmt,$bind_var,$bind_vars[$bind_var],-1)) return false;
		if (! OCIExecute($stmt)) return false;
		$num_cols = OCINumCols($stmt);
		$this->colnames = array();
		for ($i = 1; $i <= $num_cols; $i++)
		{
			$colname = OCIColumnName($stmt,$i);
			if (! preg_match(&quot;/\{hidden\}/i&quot;,$colname))
				$this->colnames[] = $colname;
		}
		// finished connecting, parsing and executing
 
You say the script crashes when ocifreestatement() is invoked and there are two instantiations of your class in the script.

How are you creating the two instantiations?
What evidence are you getting of the script's crash?

Want the best answers? Ask the best questions: TANSTAAFL!
 
I create the instances the simplest way :
Code:
...
$table = new SQLTable($user,$pass,$db);
...
...
$table = new SQLTable($user,$pass,$db);
...

I get some kind of core dump here it is :
(it is a bit long)

Code:
********** Internal heap ERROR 17112 addr=0xbf3e44 *********

***** Dump of memory around addr 0xbf3e44: 
BF3C40          00000000 00B69AD8 20000015      [....Øš¶.... ]
BF3C50 00BF3C30 00000000 00000000 00003431  [0<¿.........14..]
BF3C60 C0000061 00BF3C30 00B6B4DC 00BF3B88  [a..À0<¿.Ü´¶.ˆ;¿.]
BF3C70 48545541 5245565F 4E4F4953 4C51535F  [AUTH_VERSION_SQL]
BF3C80 C0000041 00BF3C60 00B6B4DC 00BF3B88  [A..À`<¿.Ü´¶.ˆ;¿.]
BF3C90 7250202D 6375646F 6E6F6974 C0000025  [- Production%..À]
BF3CA0 00BF3C80 00B6B4DC 00BF3B88 48545541  [€<¿.Ü´¶.ˆ;¿.AUTH]
BF3CB0 5245565F 4E4F4953 5254535F 00474E49  [_VERSION_STRING.]
BF3CC0 20000019 00BF3C30 00000000 00000000  [... 0<¿.........]
BF3CD0 5F716572 006E6567 20000019 00BF3CC0  [req_gen.... À<¿.]
BF3CE0 00000000 00000000 5F716572 006E6567  [........req_gen.]
BF3CF0 C00000A5 00BF3CD8 00BF3DC4 00BF3B88  [¥..ÀØ<¿.Ä=¿.ˆ;¿.]
BF3D00 00000000 00000001 00000002 00B7D7E0  [............à×·.]
BF3D10 00BF0710 00000000 C00000A5 00BF3CF0  [..¿.....¥..Àð<¿.]
BF3D20 00B6B4DC 00BF3B88 00000000 00000001  [Ü´¶.ˆ;¿.........]
BF3D30 00B69AD8 00B69AD8 04000400 00000000  [Øš¶.Øš¶.........]
BF3D40 00000000 00000000 00000000 00000000  [................]
        Repeat 3 times
BF3D80 20000015 00BF3CF0 00000000 00000000  [... ð<¿.........]
BF3D90 00000001 20000029 00BF3CF0 00000000  [....).. ð<¿.....]
BF3DA0 00000000 00000000 00000001 00000001  [................]
BF3DB0 00B7D7E0 00BF0710 00000000 C0000089  [à×·...¿.....‰..À]
BF3DC0 00BF3D94 00B6B4DC 00BF3CF8 00000000  [”=¿.Ü´¶.ø<¿.....]
BF3DD0 00000000 00B69AD8 00B69AD8 0000000C  [....Øš¶.Øš¶.....]
BF3DE0 00000000 00000000 00000000 00000000  [................]
        Repeat 5 times
BF3E40 00000000 00000000 00BF3DBC 00000000  [........¼=¿.....]
BF3E50 00000000 00000000 0000057B 00BF6358  [........{...Xc¿.]
BF3E60 20000029 00BF3E44 00000000 00000000  [).. D>¿.........]
BF3E70 00000000 00000001 00000001 00B7D7E0  [............à×·.]
BF3E80 00BF4550 00000000 2000050D 00BF3E60  [PE¿........ `>¿.]
BF3E90 00000000 00000000 04331816 3318112F  [..........3./..3]
BF3EA0 18282F04 00001000 00000000 00000000  [./(.............]
BF3EB0 00000000 00000000 00000000 00000000  [................]
        Repeat 13 times
BF3F90 00000000 18000000 3A043318 0433181A  [.........3.:..3.]
BF3FA0 31181B3A 00182E18 00000010 00000000  [:..1............]
BF3FB0 00000000 00000000 00000000 00000000  [................]
        Repeat 8 times
BF4040 00000000                             [....]            

******************************************************
HEAP DUMP heap name=&quot;Alloc environm&quot;  desc=0xb6b494
 extent sz=0x1024 alt=32 het=32767 rec=0 flg=3 opc=3
 parent=0 owner=0 nex=0 xsz=0x1024
EXTENT 0
  Chunk   bfe010 sz=     4124    free      &quot;               &quot;
EXTENT 1
  Chunk   bfcfd8 sz=     4124    free      &quot;               &quot;
EXTENT 2
  Chunk   bf7910 sz=     4124    free      &quot;               &quot;
EXTENT 3
  Chunk   bf68d8 sz=     4124    free      &quot;               &quot;
EXTENT 4
  Chunk   bf5808 sz=       56    freeable assoc with mark prv=0 nxt=0
  Chunk   bf5840 sz=       40    freeable assoc with mark prv=0 nxt=0
  Chunk   bf5868 sz=     1368    free      &quot;               &quot;
  Chunk   bf5dc0 sz=     1292    freeable assoc with mark prv=0 nxt=0
  Chunk   bf62cc sz=     1368    freeable assoc with mark prv=0 nxt=0
EXTENT 5
  Chunk   bf3b80 sz=      128    free      &quot;               &quot;
  Chunk   bf3c00 sz=       24    freeable assoc with mark prv=0 nxt=0
  Chunk   bf3c18 sz=       24    freeable assoc with mark prv=0 nxt=0
  Chunk   bf3c30 sz=      144    free      &quot;               &quot;
  Chunk   bf3cc0 sz=       24    freeable assoc with mark prv=0 nxt=0
  Chunk   bf3cd8 sz=       24    freeable assoc with mark prv=0 nxt=0
  Chunk   bf3cf0 sz=      164    free      &quot;               &quot;
  Chunk   bf3d94 sz=       40    freeable assoc with mark prv=0 nxt=0
  Chunk   bf3dbc sz=      136    free      &quot;               &quot;
  Chunk   bf3e44 sz=        0  ERROR, BAD MAGIC NUMBER (0)
EXTENT 6
  Chunk   bf2b48 sz=     2756    free      &quot;               &quot;
  Chunk   bf360c sz=     1368    freeable assoc with mark prv=0 nxt=0
EXTENT 7
  Chunk   bf0118 sz=      272    free      &quot;               &quot;
  Chunk   bf0228 sz=      428    freeable assoc with mark prv=0 nxt=0
  Chunk   bf03d4 sz=      336    freeable assoc with mark prv=0 nxt=0
  Chunk   bf0524 sz=      428    freeable assoc with mark prv=0 nxt=0
  Chunk   bf06d0 sz=       24    freeable assoc with mark prv=0 nxt=0
  Chunk   bf06e8 sz=       24    freeable assoc with mark prv=0 nxt=0
  Chunk   bf0700 sz=      336    freeable assoc with mark prv=0 nxt=0
  Chunk   bf0850 sz=     1292    freeable assoc with mark prv=0 nxt=0
  Chunk   bf0d5c sz=      428    freeable assoc with mark prv=0 nxt=0
  Chunk   bf0f08 sz=       28    freeable assoc with mark prv=0 nxt=0
  Chunk   bf0f24 sz=       28    freeable assoc with mark prv=0 nxt=0
  Chunk   bf0f40 sz=      336    freeable assoc with mark prv=0 nxt=0
  Chunk   bf1090 sz=      164    freeable assoc with mark prv=0 nxt=0
EXTENT 8
  Chunk   bd85c8 sz=    13584    freeable  &quot;Alloc server h &quot;  ds=b7d95c
EXTENT 9
  Chunk   b7cf10 sz=       24    perm      &quot;perm           &quot;  alo=24
  Chunk   b7cf28 sz=     2216    recreate  &quot;Alloc server h &quot;  latch=0
     ds   b7d95c sz=    15800 ct=        2
          bd85c8 sz=    13584
  Chunk   b7d7d0 sz=      500    freeable assoc with mark prv=0 nxt=0
  Chunk   b7d9c4 sz=     1368    freeable assoc with mark prv=0 nxt=0
Total heap size    =    47268
FREE LISTS:
 Bucket 0 size=272
  Chunk   bf3dbc sz=      136    free      &quot;               &quot;
  Chunk   bf3cf0 sz=      164    free      &quot;               &quot;
  Chunk   bf3b80 sz=      128    free      &quot;               &quot;
  Chunk   bf0118 sz=      272    free      &quot;               &quot;
  Chunk   bf3c30 sz=      144    free      &quot;               &quot;
 Bucket 1 size=528
 Bucket 2 size=1040
  Chunk   bf2b48 sz=     2756    free      &quot;               &quot;
  Chunk   bfe010 sz=     4124    free      &quot;               &quot;
  Chunk   bf5868 sz=     1368    free      &quot;               &quot;
  Chunk   bfcfd8 sz=     4124    free      &quot;               &quot;
  Chunk   bf7910 sz=     4124    free      &quot;               &quot;
  Chunk   bf68d8 sz=     4124    free      &quot;               &quot;
Total free space   =    21464
UNPINNED RECREATABLE CHUNKS (lru first):
PERMANENT CHUNKS:
  Chunk   b7cf10 sz=       24    perm      &quot;perm           &quot;  alo=24
Permanent space    =       24
******************************************************
 
After parse and execute the select statement,

i play my own stuff like
(i don't post the whole piece of code here. it would be irrelevant since I don't do anything weird ; just plain retrieval of the rows and formatting as a table)

Code:
while (OCIFetchInto(...))
{
   // generate my table
}

when I am done, I do the ocifreestatement() before exiting the function. But I don't need to ocifreestamement for php to crash, it just needs to free the ressource bound to my statement variable when it leaves the function.

Yesterday, I noticed that the piece of code didn't crash anymore if I pass plain string values to my constructor instead of constants defined earlier in the code. I don't see why it makes a difference since I don't reference the values but copy them into class variables. Anyhow, since I put
Code:
$table = new SQLTable(&quot;req_gen&quot;,&quot;req_gen&quot;,&quot;secapp&quot;)
php doesn't crach when freeing the statement even though the constants I used were all defined as
Code:
define(&quot;REQ_USER&quot;,&quot;req_gen&quot;);
.

I don't know if it clears things a bit for you but I must tell that I am still in the dark.

I will post a bug report to the PHP QA Team after I tested my code on a unix box. (I know we shouldn't play with Windows but they won't hear me at work when I tell them not to :) )

Thanks for helping.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top