[Xcb] [PATCH 2/2] xcb_connect_to_display_with_auth_info: Fix memory leak

Pauli Nieminen ext-pauli.nieminen at nokia.com
Fri Jun 11 06:13:42 PDT 2010


protocol and host are allocated in _xcb_parse_display but ownership of
them is passed to the caller. They have to be freed in
xcb_connect_to_display_with_auth_info.

Signed-off-by: Pauli Nieminen <ext-pauli.nieminen at nokia.com>
---
 src/xcb_util.c |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/xcb_util.c b/src/xcb_util.c
index fe1f99f..f8e2678 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -405,17 +405,21 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname,
 
     int parsed = _xcb_parse_display(displayname, &host, &protocol, &display, screenp);
     
-    if(!parsed)
-        return (xcb_connection_t *) &error_connection;
-    else
+    if(!parsed) {
+        c = (xcb_connection_t *) &error_connection;
+	goto out;
+    } else
         fd = _xcb_open(host, protocol, display);
-    free(host);
 
-    if(fd == -1)
-        return (xcb_connection_t *) &error_connection;
+    if(fd == -1) {
+        c = (xcb_connection_t *) &error_connection;
+	goto out;
+    }
 
-    if(auth)
-        return xcb_connect_to_fd(fd, auth);
+    if(auth) {
+        c = xcb_connect_to_fd(fd, auth);
+	goto out;
+    }
 
     if(_xcb_get_auth_info(fd, &ourauth, display))
     {
@@ -426,5 +430,8 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname,
     else
         c = xcb_connect_to_fd(fd, 0);
 
+out:
+    free(host);
+    free(protocol);
     return c;
 }
-- 
1.6.3.3



More information about the Xcb mailing list