[OPEN-ILS-DEV] PATCH: osrf_chat.c (memory leaks)
Scott McKellar
mck9 at swbell.net
Sat Dec 29 12:26:38 EST 2007
This patch:
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: osrf_chat_c_2.patch
Type: text/x-patch
Size: 3659 bytes
Desc: 2560643373-osrf_chat_c_2.patch
Url : http://list.georgialibraries.org/pipermail/open-ils-dev/attachments/20071229/c3ba2096/osrf_chat_c_2.bin
More information about the Open-ils-dev
mailing list