Skip to content
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

Fix memory leak of prepared queries #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stavikpetr
Copy link

@stavikpetr stavikpetr commented Sep 13, 2024

When a query is prepared with ibase_prepare() and then it is freed with ibase_free_query(), the associated zend_resource object is never freed, because the function ibase_free_query() does not decrease its ref count and it stays forever at 1 (after all the variables holding reference in php are destroyed).

I was also considering to use a following fix:

uint32_t refcount = GC_REFCOUNT(Z_RES_P(query_arg));
zend_list_close(Z_RES_P(query_arg));
if (refcount > 0) {
	zend_list_delete(Z_RES_P(query_arg));
}

This solution would avoid memory access violations in cases when the refcount is already 0 (because the zend_resource would get freed in zend_list_close()), but I would argue that this situation should never occurr and it could happen only if the internal reference created during ibase_prepare() was freed by some other parts of the code. But that is not correct and instead, it should be always freed only here.

@stavikpetr stavikpetr closed this Sep 13, 2024
@stavikpetr stavikpetr reopened this Sep 13, 2024
@stavikpetr stavikpetr changed the title ibase_free_query does not decrease ref count Fix memory leak of prepared queries Sep 13, 2024
@MartinKoeditz
Copy link
Collaborator

@stavikpetr Thank you. I will check and merge your patch next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants