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

Memory leak with callback return values #154

Open
arnetheduck opened this issue Jan 29, 2025 · 2 comments
Open

Memory leak with callback return values #154

arnetheduck opened this issue Jan 29, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@arnetheduck
Copy link
Contributor

struct miqt_array /* of QModelIndex* */ callback_return_value = miqt_exec_callback_QAbstractItemView_SelectedIndexes(const_cast<MiqtVirtualQAbstractItemView*>(this), handle__SelectedIndexes);

In this callback handler, the miqt_array is allocated on the go side but never freed. Ditto for other, similar conversions.

@mappu
Copy link
Owner

mappu commented Jan 30, 2025

The modelview example with QAbstractListModel_OnData is susceptible to this - it has to return a pointer to QVariant, because that is all that can traverse the ABI, but the Qt C++ method presumes a pass by value.

Probably, any callbacks that return a type by value (and the C ABI has to project as a pass by value) will need to destruct the value.

Currently, the destructors are embedded directly in the emitgo functions (e.g. emitParameterGo2CABIForwarding does a lot of defer C.free(...)). They'll need to be split out to separate functions and called more intelligently.

This is the dual of the problem in #86. A complete solution would fix both problems.

@mappu mappu added the bug Something isn't working label Jan 30, 2025
@arnetheduck
Copy link
Contributor Author

This bug is more about miqt_array.data which miqt_exec_callback_QAbstractItemView_SelectedIndexes allocates - after the generated code has finished iterating over the items and adding them to the list, it could free data. Ditto other similar converters (miqt_string to QString etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants