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

Scott McKellar mck9 at swbell.net
Sat Dec 1 15:02:04 EST 2007


This patch plugs some memory leaks and tidies up various things:

1. I applied the static qualifier to a number of functions, and a few
variables, that aren't referenced by other files.  I left as global
those functions that are registered for dynamic calls.

2. I found a number of cases where a call to buffer_data() was being
passed as a parameter to a function, guaranteeing a memory leak.  I
added code to capture the pointer returned by buffer_data() so that I
could free it later.

3. I added code to free a number of growing_buffers, jsonObjects,
and dynamically allocated buffers that were otherwise leaking.  In
some cases I had to juggle some extra pointers so that I could
distinguish between things I could delete and things I couldn't.  In 
other cases I rearranged operations so that the freeing wouldn't get
bypassed.  I don't guarantee that I have plugged all the leaks.

4. Whenever possible I replaced buffer_data() with buffer_release(),
to eliminate a round of malloc() and free().  In some cases this
change enabled me to eliminate an intermediate variable.

5. Whenever possible I replaced jsonObjectGetKey() with
jsonObjectGetKeyConst().  Sometimes I had to juggle an extra pointer
or two in order to distinguish between what was const and what wasn't.

6. I applied the const qualifier to a number of local variables and
function parameters.

7. Here and there I changed double leading underscores to single
leading underscores.

8. In SELECT() I commented out references to having_buf, because we
aren't actually doing anything useful with it yet.

----------

I really hadn't meant to make such extensive changes, but things
kept jumping out at me, especially the memory leaks.  I have stared
intently at the code and each change looks right.  Unfortunately I 
can't test them without building a fully functional Evergreen 
installation, which would be more work than I want to buy into just
now.  So I trust you will apply at least some rudimentary tests
before committing.

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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: oils_cstore_c_1.patch
Type: text/x-patch
Size: 51568 bytes
Desc: 3682940043-oils_cstore_c_1.patch
Url : http://list.georgialibraries.org/pipermail/open-ils-dev/attachments/20071201/bb219a8e/oils_cstore_c_1-0001.bin


More information about the Open-ils-dev mailing list