Maapi_query_free_result mem leak

Hi,
There’s a memory leak at maapi_query_free_result():

The below block should happen regardless if there are results or not, at if (qr->nresults > 0) {

if (qr->__internal) {
    ETERM *e = qr->__internal;
    erl_free_compound(e);
}

Found using valgrind.

Yeah, I’ve got this issue on ConfD 8.0.6 as well.

maapi_query_free_result() only frees the reply ETERM stored in
qr->__internal when the result chunk is non-empty. When a query chunk
comes back with zero results, the reply term is never freed, leaking the
whole 5-element tuple plus its children and the erl_malloc’ed element
block (about 500 bytes per call).

In my point of view, this should be:

        if (qr->nresults > 0) {
            ...
            free(qr->results[0].str); /* the block */
            free(qr->results);        /* the result array */
        }
        /* Free the reply term even when the query returned no results,
           otherwise every empty maapi_query_result() chunk leaks it. */
        if (qr->__internal) {
            ETERM *e = qr->__internal;
            erl_free_compound(e);
        }
        free(qr);

Any thoughts on this? Is there a ConfD version where this issue is already fixed?

Best regards,
Ittalo

Hi,

This code does not appear to have been changed at all from 8.0.6 so it seems safe to say it is behaving the same way. We will look into it.

Regards,

Scott