-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Fix GH-11878: SQLite3 callback functions cause a memory leak with a callable array #11881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@nielsdos Thank you very much. I confirmed that displays nothing about memory leak.
|
It's expected that In this case the root cause appears to be that the SQLlite3 class does not implement the Implementing a |
That makes sense. Thanks a lot for explaining to me how the collection of owned data works. I'll get to it tonight. In fact, now I also know how to fix another issue. |
…a callable array In this test file, the free_obj handler is called with a refcount of 2, caused by the fact we do a GC_ADDREF() to increase its refcount while its refcount is still 1 because the Foo object hasn't been destroyed yet (due to the cycle caused by the sqlite function callback). Solve this by introducing a get_gc handler. Closes phpGH-11881.
Fixed via get_gc now. |
…a callable array In this test file, the free_obj handler is called with a refcount of 2, caused by the fact we do a GC_ADDREF() to increase its refcount while its refcount is still 1 because the Foo object hasn't been destroyed yet (due to the cycle caused by the sqlite function callback). Solve this by introducing a get_gc handler. Closes phpGH-11881.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Looks good to me appart from nit picks.
Maybe just add an additional test in which not all functions are set, to avoid regressions. This may spot null-derefs in the future if we change the representation of the functions in php_sqlite3_db_object.
ext/sqlite3/sqlite3.c
Outdated
zend_get_gc_buffer_use(gc_buffer, table, n); | ||
} | ||
|
||
return zend_std_get_properties(object); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: zend_std_get_properties will build the property hashtable if it wasn't already. You can avoid it in two cases:
- In the
if (intern->funcs == NULL && intern->collations == NULL) {
branch, returnzend_std_get_gc(object, table, n)
- In the other branch, you can skip zend_std_get_properties() if ce->default_properties_count == 0 and object->properties is null, because it means that there are no declared nor dynamic properties
ce->default_properties_count will be > 0 in sub-classes with declared properties, and intern->std.properties will be non-null if dynamic properties was asasigned to the object.
Thank you Arnaud. Btw I've credited you as well for your help. |
In this test file, the free_obj handler is called with a refcount of 2, caused by the fact we do a GC_ADDREF() to increase its refcount while its refcount is still 1 because the Foo object hasn't been destroyed yet (due to the cycle caused by the sqlite function callback). Solve this by introducing a get_gc handler.