Unverified Commit 14df32cd authored by Mike Gabriel's avatar Mike Gabriel

Merge branch 'uli42-pr/xlib_memleak' into 3.6.x

parents ca7b3310 12b22e97
...@@ -226,6 +226,7 @@ _X11TransConnectDisplay ( ...@@ -226,6 +226,7 @@ _X11TransConnectDisplay (
p += 3; p += 3;
} }
if (pprotocol) XFree(pprotocol);
pprotocol = copystring ("nx", 2); pprotocol = copystring ("nx", 2);
if (!pprotocol) goto bad; if (!pprotocol) goto bad;
...@@ -233,7 +234,6 @@ _X11TransConnectDisplay ( ...@@ -233,7 +234,6 @@ _X11TransConnectDisplay (
#ifdef NX_TRANS_TEST #ifdef NX_TRANS_TEST
fprintf(stderr, "_X11TransConnectDisplay: Forced protocol to [%s].\n", pprotocol); fprintf(stderr, "_X11TransConnectDisplay: Forced protocol to [%s].\n", pprotocol);
#endif #endif
} }
else else
{ {
...@@ -245,9 +245,14 @@ _X11TransConnectDisplay ( ...@@ -245,9 +245,14 @@ _X11TransConnectDisplay (
* slash ('/'). * slash ('/').
*/ */
for (lastp = p; *p && *p != ':' && *p != '/'; p++) ; for (lastp = p; *p && *p != ':' && *p != '/'; p++) ;
if (!*p) return NULL; /* must have a colon */ if (!*p) /* must have a colon */
{
if (pprotocol) XFree(pprotocol);
return NULL;
}
if (p != lastp && *p != ':') { /* protocol given? */ if (p != lastp && *p != ':') { /* protocol given? */
if (pprotocol) XFree(pprotocol);
pprotocol = copystring (lastp, p - lastp); pprotocol = copystring (lastp, p - lastp);
if (!pprotocol) goto bad; /* no memory */ if (!pprotocol) goto bad; /* no memory */
p++; /* skip the '/' */ p++; /* skip the '/' */
...@@ -288,12 +293,14 @@ _X11TransConnectDisplay ( ...@@ -288,12 +293,14 @@ _X11TransConnectDisplay (
if (lastc) if (lastc)
{ {
if (phostname) XFree(phostname);
phostname = copystring (lastp, lastc - lastp); phostname = copystring (lastp, lastc - lastp);
p = lastc; p = lastc;
} }
else else
{ {
if (phostname) XFree(phostname);
phostname = copystring (lastp, strlen(lastp)); phostname = copystring (lastp, strlen(lastp));
} }
...@@ -323,7 +330,11 @@ _X11TransConnectDisplay ( ...@@ -323,7 +330,11 @@ _X11TransConnectDisplay (
if (*p == ':') if (*p == ':')
lastc = p; lastc = p;
if (!lastc) return NULL; /* must have a colon */ if (!lastc) /* must have a colon */
{
if (pprotocol) XFree(pprotocol);
return NULL;
}
if ((lastp != lastc) && (*(lastc - 1) == ':') if ((lastp != lastc) && (*(lastc - 1) == ':')
#if defined(IPv6) && defined(AF_INET6) #if defined(IPv6) && defined(AF_INET6)
...@@ -338,6 +349,7 @@ _X11TransConnectDisplay ( ...@@ -338,6 +349,7 @@ _X11TransConnectDisplay (
hostlen = lastc - lastp; hostlen = lastc - lastp;
if (hostlen > 0) { /* hostname given? */ if (hostlen > 0) { /* hostname given? */
if (phostname) XFree(phostname);
phostname = copystring (lastp, hostlen); phostname = copystring (lastp, hostlen);
if (!phostname) goto bad; /* no memory */ if (!phostname) goto bad; /* no memory */
} }
...@@ -417,7 +429,7 @@ _X11TransConnectDisplay ( ...@@ -417,7 +429,7 @@ _X11TransConnectDisplay (
if (value == NULL || strstr(value, "=") != NULL || if (value == NULL || strstr(value, "=") != NULL ||
strstr(name, ",") != NULL || strlen(value) >= 128) strstr(name, ",") != NULL || strlen(value) >= 128)
{ {
Xfree(host); if (host) Xfree(host);
goto bad; goto bad;
} }
...@@ -425,17 +437,21 @@ _X11TransConnectDisplay ( ...@@ -425,17 +437,21 @@ _X11TransConnectDisplay (
{ {
idisplay = atoi(value); idisplay = atoi(value);
if (pdpynum) XFree(pdpynum);
pdpynum = copystring(value, strlen(value)); pdpynum = copystring(value, strlen(value));
if (!pdpynum) goto bad; if (!pdpynum)
{
if (host) Xfree(host);
goto bad;
}
break; break;
} }
name = strtok(NULL, "="); name = strtok(NULL, "=");
} }
Xfree(host); if (host) Xfree(host);
if (idisplay == -1) if (idisplay == -1)
{ {
...@@ -486,6 +502,7 @@ _X11TransConnectDisplay ( ...@@ -486,6 +502,7 @@ _X11TransConnectDisplay (
if (pprotocol && !strcasecmp(pprotocol, "nx")) if (pprotocol && !strcasecmp(pprotocol, "nx"))
{ {
Xfree(pprotocol);
pprotocol = copystring ("local", 5); pprotocol = copystring ("local", 5);
if (!pprotocol) goto bad; if (!pprotocol) goto bad;
...@@ -502,18 +519,18 @@ _X11TransConnectDisplay ( ...@@ -502,18 +519,18 @@ _X11TransConnectDisplay (
if (!pprotocol) { if (!pprotocol) {
#if defined(UNIXCONN) #if defined(UNIXCONN)
if (phostname && (strcmp (phostname, "unix") == 0)) { if (phostname && (strcmp (phostname, "unix") == 0)) {
Xfree(pprotocol);
pprotocol = copystring ("unix", 4); pprotocol = copystring ("unix", 4);
} else } else
#endif #endif
#ifdef HAVE_LAUNCHD #ifdef HAVE_LAUNCHD
if (phostname && phostname[0]=='/') { if (phostname && phostname[0]=='/') {
pprotocol = copystring ("local", 5); pprotocol = copystring ("local", 5);
} }
#endif #endif
if (!phostname) if (!phostname)
{ {
if (local_transport[0] != NULL) { if (local_transport[0] != NULL) {
if (pprotocol) Xfree(pprotocol);
pprotocol = Xstrdup(local_transport[0]); pprotocol = Xstrdup(local_transport[0]);
local_transport_index = 0; local_transport_index = 0;
} }
...@@ -611,7 +628,7 @@ _X11TransConnectDisplay ( ...@@ -611,7 +628,7 @@ _X11TransConnectDisplay (
} }
#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST) #if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
fprintf(stderr, "_X11TransConnectDisplay: Out of connection loop.\n"); fprintf(stderr, "_X11TransConnectDisplay: Out of connection loop.\n");
#endif #endif
if (address != addrbuf) Xfree (address); if (address != addrbuf) Xfree (address);
address = addrbuf; address = addrbuf;
...@@ -636,7 +653,7 @@ _X11TransConnectDisplay ( ...@@ -636,7 +653,7 @@ _X11TransConnectDisplay (
* XDisplayString() and XDisplayName() agree. * XDisplayString() and XDisplayName() agree.
*/ */
if (reset_hostname && (phostname != original_hostname)) { if (reset_hostname && (phostname != original_hostname)) {
Xfree (phostname); if (phostname) Xfree (phostname);
phostname = original_hostname; phostname = original_hostname;
original_hostname = NULL; original_hostname = NULL;
} }
...@@ -668,7 +685,6 @@ _X11TransConnectDisplay ( ...@@ -668,7 +685,6 @@ _X11TransConnectDisplay (
#if defined(LOCALCONN) || defined(UNIXCONN) || defined(TCPCONN) #if defined(LOCALCONN) || defined(UNIXCONN) || defined(TCPCONN)
if (original_hostname) Xfree (original_hostname); if (original_hostname) Xfree (original_hostname);
#endif #endif
GetAuthorization(trans_conn, family, (char *) saddr, saddrlen, idisplay, GetAuthorization(trans_conn, family, (char *) saddr, saddrlen, idisplay,
auth_namep, auth_namelenp, auth_datap, auth_datalenp); auth_namep, auth_namelenp, auth_datap, auth_datalenp);
return trans_conn; return trans_conn;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment