summaryrefslogtreecommitdiff
path: root/src/xcb_util.c
diff options
context:
space:
mode:
authorPauli Nieminen <ext-pauli.nieminen@nokia.com>2010-06-11 16:30:46 +0300
committerPeter Harris <pharris@opentext.com>2010-06-15 13:16:45 -0400
commit18718d483e0982c779a61c71176fb0e64f850015 (patch)
tree1d3cac5be8ce72abb42ae3622f4d992e7b4910a8 /src/xcb_util.c
parent3f79628becbd3b0eff1aef804902eb739fac4403 (diff)
_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 <ext-pauli.nieminen@nokia.com> Signed-off-by: Peter Harris <pharris@opentext.com>
Diffstat (limited to 'src/xcb_util.c')
-rw-r--r--src/xcb_util.c19
1 files 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,