xcb_disconnect(): Fix leak with error connections
authorUli Schlachter <psychon@znc.in>
Tue, 31 Dec 2013 14:05:36 +0000 (15:05 +0100)
committerUli Schlachter <psychon@znc.in>
Fri, 21 Mar 2014 13:38:58 +0000 (14:38 +0100)
commit4dcbfd77b78ca6b016ce815af26235501f6cd75a
tree3c848875f27c3f98df05b31b2e6cc27d3996e1b2
parentd84dd752ef571491b015443fefedca53c7f81282
xcb_disconnect(): Fix leak with error connections

There are two kind of error connections in XCB. First, if something goes wrong
while the connection is being set up, _xcb_conn_ret_error() is used to return a
static connection in an error state. If something goes wrong later,
_xcb_conn_shutdown() is used to set c->has_error.

This is important, because the static object that _xcb_conn_ret_error() returns
must not be freed, while the dynamically allocated objects that go through
_xcb_conn_shutdown() must obviously be properly deallocated.

This used to work correctly, but in 769acff0da8, xcb_disconnect() was made to
ignore all connections in an error state completely. Fix this by only ignoring
the few static error connections that we have.

This was tested with the following hack:

    xcb_connection_t *c = xcb_connect(NULL, NULL);
    close(xcb_get_file_descriptor(c));
    xcb_discard_reply(c, xcb_get_input_focus(c).sequence);
    xcb_flush(c);
    xcb_disconnect(c);

Valgrind confirms that xcb has a memory leak before this patch that this patch
indeed fixes.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Reviewed-by: Julien Cristau <jcristau@debian.org>
src/xcb_conn.c