You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OCI_RETURN_LOBS flag causes oci8 to leak memory #18873
php/pecl-database-oci8#29 fixed memory leak once after 8th descriptor create, and such fix can be backported into PHP 8.3 however it is not critical and maybe it can be even considered a feature.
This issue is about a clear memory leak after every iteration when the data are fetched using OCI_RETURN_LOBS flag. Such flag imply the data are not returned as descriptor, but as a string instead. So it seems the descriptor is somehow not released after the data are read.
This is a matter of when the descriptor, which is a zend_resource, gets freed.
First, regardless of the OCI_RETURN_LOBS flag, the descriptor's reference count is decremented in php_oci_column_hash_dtor(). If the reference count is 1 at that point, zend_list_close() is called.
However, since it is called when the reference count is 1, this alone does not fully destroy the resource. As a result, remnants remain until the end of the script, leading to increased memory usage.
When the OCI_RETURN_LOBS flag is not used, memory usage remains stable because the descriptor is registered as a property of a zend_object (which increases the reference count by 1). In this case, zend_list_close() is not called in php_oci_column_hash_dtor(), it simply decrements the reference count.
Subsequently, the descriptor is destroyed along with the destruction of the zend_object, so it does not persist until the end of the script.
Activity
mvorisek commentedon Jun 19, 2025
The only usafe of the problematic
OCI_RETURN_LOBSflag is in https://github.com/php/php-src/blob/php-8.3.22/ext/oci8/oci8.c#L1571. Any idea what is wrong with this part of code?SakiTakamachi commentedon Jun 27, 2025
This is a matter of when the
descriptor, which is azend_resource, gets freed.First, regardless of the
OCI_RETURN_LOBSflag, thedescriptor's reference count is decremented inphp_oci_column_hash_dtor(). If the reference count is1at that point,zend_list_close()is called.However, since it is called when the reference count is
1, this alone does not fully destroy the resource. As a result, remnants remain until the end of the script, leading to increased memory usage.php-src/ext/oci8/oci8.c
Line 577 in e892356
When the
OCI_RETURN_LOBSflag is not used, memory usage remains stable because thedescriptoris registered as a property of azend_object(which increases the reference count by1). In this case,zend_list_close()is not called inphp_oci_column_hash_dtor(), it simply decrements the reference count.Subsequently, the
descriptoris destroyed along with the destruction of thezend_object, so it does not persist until the end of the script.php-src/ext/oci8/oci8.c
Line 1596 in e892356
Fix GH-18873 - Free column->descid appropriately (#18957)
Merge branch 'PHP-8.3' into PHP-8.4
Merge branch 'PHP-8.4'