From 18718d483e0982c779a61c71176fb0e64f850015 Mon Sep 17 00:00:00 2001 From: Pauli Nieminen Date: Fri, 11 Jun 2010 16:30:46 +0300 Subject: _xcb_parse_display: Fix error path xcb_parse_display claims that there is no side effects when failing. That requires _xcb_parse_display to free the memory in failure case. Signed-off-by: Pauli Nieminen Signed-off-by: Peter Harris --- src/xcb_util.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/xcb_util.c b/src/xcb_util.c index 8c2a031..fe1f99f 100644 --- a/src/xcb_util.c +++ b/src/xcb_util.c @@ -64,6 +64,7 @@ static int _xcb_parse_display(const char *name, char **host, char **protocol, { int len, display, screen; char *slash, *colon, *dot, *end; + if(!name || !*name) name = getenv("DISPLAY"); if(!name) @@ -92,35 +93,43 @@ static int _xcb_parse_display(const char *name, char **host, char **protocol, colon = strrchr(name, ':'); if(!colon) - return 0; + goto error_out; len = colon - name; ++colon; display = strtoul(colon, &dot, 10); if(dot == colon) - return 0; + goto error_out; if(*dot == '\0') screen = 0; else { if(*dot != '.') - return 0; + goto error_out; ++dot; screen = strtoul(dot, &end, 10); if(end == dot || *end != '\0') - return 0; + goto error_out; } /* At this point, the display string is fully parsed and valid, but * the caller's memory is untouched. */ *host = malloc(len + 1); if(!*host) - return 0; + goto error_out; memcpy(*host, name, len); (*host)[len] = '\0'; *displayp = display; if(screenp) *screenp = screen; return 1; + +error_out: + if (protocol) { + free(*protocol); + *protocol = NULL; + } + + return 0; } int xcb_parse_display(const char *name, char **host, int *displayp, -- cgit v1.2.3