Python bindings leak the QofSession/QofBook (and Query)

John Ralls jralls at ceridwen.us
Sun Jul 12 14:45:30 EDT 2026



> On Jul 11, 2026, at 12:45, array_hourly_0u at icloud.com wrote:
> 
> Is a finalizer wanted here at all, or is explicit lifetime management
> (with / destroy) the intended contract for the Python bindings? And if
> a finalizer is acceptable, do you prefer the Python-wrapper approach
> or the SWIG thisown approach?

Well, explicit lifetime management is the contract on the C side.

A complication in either of your proposals is that gnc_get_current_session isn’t necessarily borrowed: If there is no current session then it calls gnc_session_new(). Since it also creates a book for the session it’s really the preferred constructor, but unfortunately qof_session_new is used directly in a few places. The only really safe way to have shared ownership—a requirement for automatic destruction in a GC binding--is with properly-used shared pointers. GObject provides C shared pointers but they have to be manually reffed and unreffed and our current code either ignores that feature altogether or isn’t always consistent about it. C++ std::shared_ptrs are automatic but can’t be used directly from C. 

Regards,
John Ralls

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20260712/a35545f7/attachment.htm>


More information about the gnucash-devel mailing list