[OPEN-ILS-DEV] PATCH: osrf_json_object.c (miscellaneous)

Scott McKellar mck9 at swbell.net
Sat Dec 8 20:14:38 EST 2007


--- Mike Rylander <mrylander at gmail.com> wrote:

> The other part that I'm not positive about, but I believe to be true
> (and coded for),  is that osrfAppRespond() takes care of destroying
> the object it is passed.  Basically, I'm not freeing anything that
> comes out of the ctx object (hash, and all its descendants), nor
> anything I return to the client.

If you are referring to the second parameter of osrfAppRespond(),
which is a const jsonObject*, the answer is no -- that object doesn't
get freed.  In fact osrfAppRespond can't free it, at least not without
a loathsome cast, because of the constness.

So I think this is indeed a leak.  We call osrfAppRespond in line
2433:

        osrfAppRespond( ctx, oilsMakeJSONFromResult( result ) );

The second parameter is a newly allocated jsonObject created by
oilsMakeJSONFromResult().  That object never gets freed.  We need to
capture the pointer in a variable, pass the variable as a parameter,
and then free it via jsonObjectFree():

        jsonObject * resultObj = oilsMakeJSONFromResult( result );
        osrfAppRespond( ctx, resultObj ):
        jsonObjectFree( resultObj );

Scott McKellar
http://home.swbell.net/mck9/ct/







More information about the Open-ils-dev mailing list