Bug 30343 - XCB leaks memory and socket file descriptor on connection failure.
Summary: XCB leaks memory and socket file descriptor on connection failure.
Status: RESOLVED FIXED
Alias: None
Product: XCB
Classification: Unclassified
Component: Library (show other bugs)
Version: unspecified
Hardware: All All
: medium normal
Assignee: Josh Triplett
QA Contact: xcb mailing list dummy
URL:
Whiteboard:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2010-09-23 05:04 UTC by jp.sittingduck
Modified: 2010-09-23 15:09 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
A test-case to show leak. (878 bytes, text/x-csrc)
2010-09-23 05:04 UTC, jp.sittingduck
Details
Here is my proposed patch. (1.47 KB, patch)
2010-09-23 05:06 UTC, jp.sittingduck
Details | Splinter Review
Patch to allow disconnecting connections in the error state (1.75 KB, patch)
2010-09-23 14:19 UTC, Josh Triplett
Details | Splinter Review

Description jp.sittingduck 2010-09-23 05:04:14 UTC
Created attachment 38899 [details]
A test-case to show leak.

When there is a connection error, XCB sets has_error to 1 in xcb_connection_t, which precludes clean-up (since, if has_error is set to 1, the connection may be a pointer to the error_connection variable). Attached is a test-case that simulates a connection failure. Running it in valgrind will show not only a memory leak, but a file descriptor leak (the socket) too.
Comment 1 jp.sittingduck 2010-09-23 05:06:53 UTC
Created attachment 38900 [details] [review]
Here is my proposed patch.

This is my proposed patch that adds an is_open field to xcb_connection_t, which is checked in xcb_disconnect so that an open connection can be cleaned up despite having had an error.

error_connection in xcb_conn.c is changed from an int to an xcb_connection_t, with has_error and is_open set to 1 and 0 respectively.
Comment 2 Jamey Sharp 2010-09-23 12:04:06 UTC
In an amusing coincidence, Josh has a different patch sitting in his queue that we wrote last week for this same issue. Josh?
Comment 3 Josh Triplett 2010-09-23 14:19:54 UTC
Created attachment 38920 [details] [review]
Patch to allow disconnecting connections in the error state

Jamey and I wrote the attached patch on the plane back from XDS 2010:

Subject: [PATCH] Allow disconnecting connections that are in error state.

In support of this, consolidate the two static error_connection
definitions into one so we don't try to free the static out-of-memory
error_connection.

Commit by Josh Triplett and Jamey Sharp.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
Comment 4 Josh Triplett 2010-09-23 15:09:47 UTC
I confirmed that the test case no longer leaks the connection when used with this patch, so I've pushed the patch to libxcb master.  Closing this bug.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.