GnuCash
Contact   Instructions
Bug 796750 - qof_query_search_for stores pointer of type string argument
Summary: qof_query_search_for stores pointer of type string argument
Status: REOPENED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: Engine (show other bugs)
Version: 3.2
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: core
QA Contact: core
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 796863
  Show dependency tree
 
Reported: 2018-07-11 04:00 EDT by David
Modified: 2019-01-26 05:12 EST (History)
4 users (show)

See Also:


Attachments

Description David 2018-07-11 04:00:47 EDT
qof_query_search_for stores the pointer of the QofIdType argument without copying the string.
This causes queries using the python 3 bindings to fail because the QofIdType argument pointer is invalid by the time the query is run as the QofidType argument string is only valid for the lifetime of the wrapper function for qof_query_search_for.
Comment 1 Derek Atkins 2018-07-12 10:12:10 EDT
This API is working as specified.  The QofIdType is a static constant, and this API specifies that it store the pointer thereto.

The Python binding needs to work with the C API specification, not the other way around.
Comment 2 John Ralls 2018-07-12 15:34:23 EDT
Not only is the API not specified or documented anywhere, it's utterly non-bindable. There's no way to get a static string from either Guile or Python.

The problem applies to both qof_query_search_for and qof_query_create_for.

The straight Guile wrappers don't work either: They just cast the SCM argument to a QofIdTypeConst and hand it over. That doesn't produce a usable char*. Naturally the non-working bindings aren't called anywhere. Actual code uses qof-query-create-for-splits and qof-query-create-for-invoices (engine.i and business-core.i, respectively; neither exported to Python) and the elaborate gnc_scm2query_v2 in engine-helpers.c that gets the string value from an SCM symbol, converts it to UTF8, strdups that to pass to qof_query_search_for, *then frees the search_for string*. It's pure luck if the query gets run before the string location is overwritten. Fortunately it's used only in the register report.

The simplest solution is to strdup the QofIdType and free it when it's replaced or the query is destroyed.
Comment 3 John Ralls 2018-09-08 16:56:04 EDT
Christoff Holterman has devised a work-around for Python to fix bug 796137. This is technically a duplicate of that but covers both Python and Guile so I'm leaving this open.

Note You need to log in before you can comment on or make changes to this bug.