[Xcb] [PATCH v2 1/2] _xcb_parse_display: Fix error path
Pauli Nieminen
ext-pauli.nieminen at nokia.com
Fri Jun 11 06:30:46 PDT 2010
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 at nokia.com>
---
src/xcb_util.c | 19 ++++++++++++++-----
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,
--
1.6.3.3
More information about the Xcb
mailing list