kubo / ruby-oci8

Ruby-oci8 - Oracle interface for ruby
Other
169 stars 75 forks source link

Function oci8_lob_read not closing LOB's #134

Closed ZaWertun closed 8 years ago

ZaWertun commented 8 years ago

When lob_close called from oci8_lob_read it's doing nothing. Function lob_close checks for lob->state == S_OPEN, but lob->state has value S_NO_OPEN_CLOSE in that case.

Also if LOB is temporary it must be freed with OCILobFreeTemporary function before closing it (somewhere in lob_close?). Without call to OCILobFreeTemporary simple SQL like select e.xmltype_col.getClobVal() from tmp e can cause huge memory leak on server side.

kubo commented 8 years ago

Thanks for the report. I'll check it.

kubo commented 8 years ago

IMO there is no problem. But I checked it several years ago. I forget what I checked. I'll check it again.

When a LOB is temporary and is freed or GC'ed, the associated LOB locator is linked to svcctx->temp_lobs because SEGV may occur if OCILobFreeTemporar is called in some situations. The lob locators are freed later.

ZaWertun commented 8 years ago

Thanks for investigating. Maybe then I'm doing something wrong... All in all I change my script to close session after reading every 250k rows and that helped me to work around server memory leak (entire select returns about 42 millions of rows).