[Xcb] [PATCH 2/2] Make xcb_disconnect(NULL) safe
Uli Schlachter
psychon at znc.in
Wed Feb 19 12:34:04 PST 2014
Code can be simplified if the deallocation functions can always be called in
cleanup code. So if you have some code that does several things that can go
wrong, one of which is xcb_connect(), after this change, the xcb_connection_t*
variable can be initialized to NULL and xcb_disconnect() can always be called on
the connection object.
References: http://lists.freedesktop.org/archives/xcb/2013-September/008659.html
Signed-off-by: Uli Schlachter <psychon at znc.in>
---
src/xcb.h | 2 +-
src/xcb_conn.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/xcb.h b/src/xcb.h
index 73c77a3..812f54a 100644
--- a/src/xcb.h
+++ b/src/xcb.h
@@ -484,7 +484,7 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info);
* @param c: The connection.
*
* Closes the file descriptor and frees all memory associated with the
- * connection @c c.
+ * connection @c c. If @p c is @c NULL, nothing is done.
*/
void xcb_disconnect(xcb_connection_t *c);
diff --git a/src/xcb_conn.c b/src/xcb_conn.c
index 528afab..a5ff6c4 100644
--- a/src/xcb_conn.c
+++ b/src/xcb_conn.c
@@ -350,7 +350,7 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
void xcb_disconnect(xcb_connection_t *c)
{
- if(is_static_error_conn(c))
+ if(c == NULL || is_static_error_conn(c))
return;
free(c->setup);
--
1.8.5.3
More information about the Xcb
mailing list