_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>
This commit is contained in:
parent
3f79628bec
commit
18718d483e
|
@ -64,6 +64,7 @@ static int _xcb_parse_display(const char *name, char **host, char **protocol,
|
||||||
{
|
{
|
||||||
int len, display, screen;
|
int len, display, screen;
|
||||||
char *slash, *colon, *dot, *end;
|
char *slash, *colon, *dot, *end;
|
||||||
|
|
||||||
if(!name || !*name)
|
if(!name || !*name)
|
||||||
name = getenv("DISPLAY");
|
name = getenv("DISPLAY");
|
||||||
if(!name)
|
if(!name)
|
||||||
|
@ -92,35 +93,43 @@ static int _xcb_parse_display(const char *name, char **host, char **protocol,
|
||||||
|
|
||||||
colon = strrchr(name, ':');
|
colon = strrchr(name, ':');
|
||||||
if(!colon)
|
if(!colon)
|
||||||
return 0;
|
goto error_out;
|
||||||
len = colon - name;
|
len = colon - name;
|
||||||
++colon;
|
++colon;
|
||||||
display = strtoul(colon, &dot, 10);
|
display = strtoul(colon, &dot, 10);
|
||||||
if(dot == colon)
|
if(dot == colon)
|
||||||
return 0;
|
goto error_out;
|
||||||
if(*dot == '\0')
|
if(*dot == '\0')
|
||||||
screen = 0;
|
screen = 0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(*dot != '.')
|
if(*dot != '.')
|
||||||
return 0;
|
goto error_out;
|
||||||
++dot;
|
++dot;
|
||||||
screen = strtoul(dot, &end, 10);
|
screen = strtoul(dot, &end, 10);
|
||||||
if(end == dot || *end != '\0')
|
if(end == dot || *end != '\0')
|
||||||
return 0;
|
goto error_out;
|
||||||
}
|
}
|
||||||
/* At this point, the display string is fully parsed and valid, but
|
/* At this point, the display string is fully parsed and valid, but
|
||||||
* the caller's memory is untouched. */
|
* the caller's memory is untouched. */
|
||||||
|
|
||||||
*host = malloc(len + 1);
|
*host = malloc(len + 1);
|
||||||
if(!*host)
|
if(!*host)
|
||||||
return 0;
|
goto error_out;
|
||||||
memcpy(*host, name, len);
|
memcpy(*host, name, len);
|
||||||
(*host)[len] = '\0';
|
(*host)[len] = '\0';
|
||||||
*displayp = display;
|
*displayp = display;
|
||||||
if(screenp)
|
if(screenp)
|
||||||
*screenp = screen;
|
*screenp = screen;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
error_out:
|
||||||
|
if (protocol) {
|
||||||
|
free(*protocol);
|
||||||
|
*protocol = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xcb_parse_display(const char *name, char **host, int *displayp,
|
int xcb_parse_display(const char *name, char **host, int *displayp,
|
||||||
|
|
Loading…
Reference in New Issue