History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: LM-95
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Mikael Hallendal
Reporter: Daniel Lavalliere
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Loudmouth

File descriptor leak in lm-connection.c

Created: 13/Apr/07 06:21 PM   Updated: 24/Sep/08 03:06 PM
Component/s: None
Affects Version/s: 1.2.1
Fix Version/s: 1.3.4


 Description  « Hide
On retries due to errors, the file descriptor is not closed in lm-connection.c:
If in _lm_connection_failed_with_error(...), the condition (connect_data->current_addr == NULL) is false,
connection_do_connect(...) is called and creates a new socket that is immediatly assigned with
connect_data->fd = fd, not closing the current fd if not 1. If the condition (connect_data>current_addr == NULL) is true,
connection_do_close(...) is called and fd set to -1 but was never closed.

 All   Comments   Change History      Sort Order:
Owen Taylor - [25/Apr/07 01:45 PM ]
This is a slightlyb confusing description of the problem; as far as I can see, has nothing to do with
retries; it happens on every failed connection. The real problem is described in a FIXME in
the current code.

if (connect_data->io_channel != NULL) { g_io_channel_unref (connect_data->io_channel); /* FIXME: need to check for last unref and close the socket */ }

(The FIXME, but no fix was added at some point between the 1.0.5 code
where I noticed the leak and 1.2.1; in 1.3.x the FIXME and bug have migrated to lm-socket.c)

In 1.2.1, there was also added in a couple of code paths an explicit call to _lm_sock_close()
apparently as a workaround for this? Without a lot of detailed analysis, I'd suggest one of
two fixes:

A) Just set the channel close_on_unref() immediately after creating it, and don't close the
socket in any other way.

B) Dont' use close_on_unref() (I presonally would never use close_on_unref() on an
iochannel where I'm mixing raw socket API with GIOChannel API) and add an internal
function that closes the socket, unrefs the channel and sets fd and sock to NULL.

[ Obviously fixing is cmplicated by the fact that 1.2.1 and 1.3.x have very different code
structure in this area. ]


Mikael Hallendal - [25/Apr/07 01:52 PM ]
Thanks for the description Owen. The move to 1.3.x was a first move to clean this mess up.

The code have been migrating over a long time with support for SSL and proxy as well as other features added after the initial write.

I've decided to drop the 1.3 branch and will move to 1.9 and then 2.0 which will provide a proper XMPP support.

One of the remaining issues is to clean up the socket code (and potentially replace it by a better implementation all together, I've been looking at the socket code from Libsoup but there are a few others as well).

The _lm_sock parts were added while we made sure that it ran properly on Windows and also as a way to split (sadly not fully) the socket code from the Jabber-logics in LmConnection.


Mikael Hallendal - [29/Apr/07 10:04 AM ]
Set the 1.2 target.

Mikael Hallendal - [28/Feb/08 02:22 AM ]
Fixed this in the 1.3 branch, should be in the 1.3.4 release.

Commit 68ac1c9cc9aa543d5441cdad0d2f01ef44769f5d