[OPEN-ILS-DEV] PATCH: oils_cstore.c (memory leaks)

Mike Rylander mrylander at gmail.com
Sun Feb 3 14:36:55 EST 2008


On Feb 3, 2008 12:42 PM, Scott McKellar <mck9 at swbell.net> wrote:
> This patch focusses on a number of memory leaks, all of them involving
> character strings allocated by jsonObjectToSimpleString().  It also
> rearranges a few other things along the way.

Very adventurous!  Applied with my thanks.

>
> 1. In setSavepoint(), releaseSavepoint() and rollbackSavepoint()
> we were leaking spName.
>
> 2. Deep in doCreate() we were passing the return value of
> jsonObjectToSimpleString() directly to strcmp(), resulting in a leak.
> The strcmp() was inside a complex if condition. which I rearranged so
> as to capture the string and free it.
>
> Also: I captured and reused the return value from
> jsonObjectGetKeyConst() so as to avoid duplicated calls.
>
> Aso: I reversed the sense of the if condition and swapped the branches,
> so that it tests for equality rather than inequality.  To my eyes this
> arrangement is more readable.
>
> 3. doRetrieve() was leaking id.
>
> 4. jsonNumberToDBString() was passing the return value of
> jsonObjectToSimpleString() directly to atol() and atof(), thereby
> leaking the memory.  I captured the pointers and freed them.
>
> 5. searchFieldTransform() was leaking val.
>
> 6. In searchJOIN() we were leaking type and filter_op in the case of
> some early returns.  I moved the allocations past the early returns
> so that we don't allocate them until we need them.  I also free them
> as soon as we are done with them.  As a side benefit, I was able to
> avoid allocating filter_op at all in some cases.
>
> I gave similar treatment to table, although that wasn't being leaked.
> As a result I could avoid having to free it in the early returns.
>
> A couple of the early returns would leak field or fkey.  I plugged
> those leaks as well.
>
> I moved the declarations of filter and join_filter to their points
> of first use, in the interest of clarity.
>
> 7. In buildSELECT(): we were passing the return value of
> jsonObjectToSimpleString() directly to osrfHashGet(), thereby leaking
> the memory.  I captured the pointer and freed it.
>
> 8. In doFieldmapperSearch() a do/while loop allocates pkey_val but
> in some cases wasn't freeing it.
>
> Scott McKellar
> http://home.swbell.net/mck9/ct/
>
> Developer's Certificate of Origin 1.1 By making a contribution to
> this project, I certify that:
>
> (a) The contribution was created in whole or in part by me and I
> have the right to submit it under the open source license indicated
> in the file; or
>
> (b) The contribution is based upon previous work that, to the best
> of my knowledge, is covered under an appropriate open source license
> and I have the right under that license to submit that work with
> modifications, whether created in whole or in part by me, under the
> same open source license (unless I am permitted to submit under a
> different license), as indicated in the file; or
>
> (c) The contribution was provided directly to me by some other person
> who certified (a), (b) or (c) and I have not modified it; and
>
> (d) In the case of each of (a), (b), or (c), I understand and agree
> that this project and the contribution are public and that a record
> of the contribution (including all personal information I submit
> with it, including my sign-off) is maintained indefinitely and may
> be redistributed consistent with this project or the open source
> license indicated in the file.



-- 
Mike Rylander
 | VP, Research and Design
 | Equinox Software, Inc. / The Evergreen Experts
 | phone:  1-877-OPEN-ILS (673-6457)
 | email:  miker at esilibrary.com
 | web:  http://www.esilibrary.com


More information about the Open-ils-dev mailing list