[gnet] Memory leak in GConn in GNet 1.4
- From: Matt Campbell <mattcampbell pobox com>
- To: gnet gnetlibrary org
- Subject: [gnet] Memory leak in GConn in GNet 1.4
- Date: Sat, 13 Jul 2002 17:51:24 -0500
Suppose a program using GConn allocates a buffer, passes that buffer
to gnet_conn_write, and loses its pointer to that buffer (as
echoserver does). If the write succeeds, then conn->func can free
the buffer. If the program needs to call gnet_conn_disconnect or
gnet_conn_delete before the write has completed or failed, the
buffer will also be freed, assuming the delete_buffers parameter
passed to that function is TRUE.
However, if a write error or timeout occurs, the buffer will not
be freed until the program exits. This is so for two reasons:
1. conn_write_cb doesn't pass a pointer to the buffer to conn->func
unless the write succeeded, so conn->func can't free the buffer if
the write failed.
2. When write_async_cb and write_async_timeout_cb (in iochannel.c)
call gnet_io_channel_write_async_cancel, they always pass a false
delete_buffers parameter to that function.
One possible solution to this problem would be for conn_write_cb
to pass a pointer to the buffer to conn->func when the write fails.
Then, conn->func can check for a non-null buffer parameter if the
status is GNET_CONN_STATUS_ERROR, and if there is one, free the
buffer. There are other solutions as well, but this one is the
most consistent with the way GConn already works in other cases.
I hope this helps. If I am wrong about this, please explain why.
Thanks.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]