Make xcb_disconnect(NULL) safe
authorUli Schlachter <psychon@znc.in>
Tue, 31 Dec 2013 14:18:01 +0000 (15:18 +0100)
committerUli Schlachter <psychon@znc.in>
Fri, 21 Mar 2014 13:39:44 +0000 (14:39 +0100)
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@znc.in>
Reviewed-by: Julien Cristau <jcristau@debian.org>
src/xcb.h
src/xcb_conn.c

index 148b00c..c17a2ef 100644 (file)
--- a/src/xcb.h
+++ b/src/xcb.h
@@ -483,7 +483,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);
 
index ab901a9..fa50985 100644 (file)
@@ -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);