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

Mike Rylander mrylander at gmail.com
Mon Dec 31 21:24:16 EST 2007


On Dec 29, 2007 12:26 PM, Scott McKellar <mck9 at swbell.net> wrote:
> This patch:

is also applied.

>
> 1. Makes sure that all members of OsrfChatServer and OsrfChatNode are
> explicitly initialized;
>
> 2. Plugs several actual or potential memory leaks.
>
> Commentary:
>
> 1. One way to leak memory is to overwrite a non-NULL pointer without
> freeing the thing that it pointed to.  However it can be difficult to
> determine, by inspecting the code, whether the pointer might have
> been non-NULL in the first place.
>
> In several cases, rather than try to analyze the entire flow of the
> program, I just threw in a test for NULL and freed the pointer if
> it wasn't NULL.
>
> It may be that these weren't leaks at all, in which case my additions
> will waste a few machine cycles.  At least we can be confident that
> we aren't leaking, regardless of how the rest of the program behaves.
>
> 2. When destroying an OsrfChatServer, we dutifully free mgr, which
> is a pointer to a socket manager.
>
> However a socket_manager owns a linked list of socket_nodes, each of
> which owns a socket.  I saw no sign that we were necessarily freeing
> all the socket_nodes or closing the sockets.
>
> Were I to analyze the program more carefully, I might determine that
> in practice we don't destroy the osrfChatServer until we have already
> cleared out the list of socket_nodes.
>
> But I was too lazy to do that.  So I replaced the free() with a call
> to socket_manager_free().  At worst I may be wasting a few machine
> cycles, but we can be more confident that we are leaking neither
> socket_nodes nor sockets.
>
> 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