Skip to content

Commit 12b22e9

Browse files
uli42sunweaver
authored andcommitted
yConnDis.c: fix memory leak
Direct leak of 3 byte(s) in 1 object(s) allocated from: #0 0xb79e85d4 in __interceptor_malloc (/lib/i386-linux-gnu/libasan.so.5+0xeb5d4) #1 0xb770b635 in copystring /home/uli/work/nx/nx-libs/nx-X11/lib/src/ConnDis.c:96 #2 0xb770ba56 in _X11TransConnectDisplay /home/uli/work/nx/nx-libs/nx-X11/lib/src/ConnDis.c:229 #3 0xb776b4fd in XOpenDisplay /home/uli/work/nx/nx-libs/nx-X11/lib/src/OpenDis.c:215 ArcticaProject#4 0x63e2fd in nxagentInternalOpenDisplay /home/uli/work/nx/nx-libs/nx-X11/programs/Xserver/hw/nxagent/Display.c:608 ArcticaProject#5 0x63fa03 in nxagentOpenDisplay /home/uli/work/nx/nx-libs/nx-X11/programs/Xserver/hw/nxagent/Display.c:1140 ArcticaProject#6 0x694b5a in InitOutput /home/uli/work/nx/nx-libs/nx-X11/programs/Xserver/hw/nxagent/Init.c:305 ArcticaProject#7 0x5f7b11 in main /home/uli/work/nx/nx-libs/nx-X11/programs/Xserver/dix/main.c:278 ArcticaProject#8 0xb6f04b40 in __libc_start_main ../csu/libc-start.c:308 I have not investigated the exact location where an XFree() was missing but added multiple Xfree() calls whereever appropriate. Fixes ArcticaProject#951
1 parent ca7b331 commit 12b22e9

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

nx-X11/lib/src/ConnDis.c

+28-12
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ _X11TransConnectDisplay (
226226
p += 3;
227227
}
228228

229+
if (pprotocol) XFree(pprotocol);
229230
pprotocol = copystring ("nx", 2);
230231

231232
if (!pprotocol) goto bad;
232233

233234
#ifdef NX_TRANS_TEST
234235
fprintf(stderr, "_X11TransConnectDisplay: Forced protocol to [%s].\n", pprotocol);
235236
#endif
236-
237237
}
238238
else
239239
{
@@ -245,9 +245,14 @@ _X11TransConnectDisplay (
245245
* slash ('/').
246246
*/
247247
for (lastp = p; *p && *p != ':' && *p != '/'; p++) ;
248-
if (!*p) return NULL; /* must have a colon */
248+
if (!*p) /* must have a colon */
249+
{
250+
if (pprotocol) XFree(pprotocol);
251+
return NULL;
252+
}
249253

250254
if (p != lastp && *p != ':') { /* protocol given? */
255+
if (pprotocol) XFree(pprotocol);
251256
pprotocol = copystring (lastp, p - lastp);
252257
if (!pprotocol) goto bad; /* no memory */
253258
p++; /* skip the '/' */
@@ -288,12 +293,14 @@ _X11TransConnectDisplay (
288293

289294
if (lastc)
290295
{
296+
if (phostname) XFree(phostname);
291297
phostname = copystring (lastp, lastc - lastp);
292298

293299
p = lastc;
294300
}
295301
else
296302
{
303+
if (phostname) XFree(phostname);
297304
phostname = copystring (lastp, strlen(lastp));
298305
}
299306

@@ -323,7 +330,11 @@ _X11TransConnectDisplay (
323330
if (*p == ':')
324331
lastc = p;
325332

326-
if (!lastc) return NULL; /* must have a colon */
333+
if (!lastc) /* must have a colon */
334+
{
335+
if (pprotocol) XFree(pprotocol);
336+
return NULL;
337+
}
327338

328339
if ((lastp != lastc) && (*(lastc - 1) == ':')
329340
#if defined(IPv6) && defined(AF_INET6)
@@ -338,6 +349,7 @@ _X11TransConnectDisplay (
338349
hostlen = lastc - lastp;
339350

340351
if (hostlen > 0) { /* hostname given? */
352+
if (phostname) XFree(phostname);
341353
phostname = copystring (lastp, hostlen);
342354
if (!phostname) goto bad; /* no memory */
343355
}
@@ -417,25 +429,29 @@ _X11TransConnectDisplay (
417429
if (value == NULL || strstr(value, "=") != NULL ||
418430
strstr(name, ",") != NULL || strlen(value) >= 128)
419431
{
420-
Xfree(host);
432+
if (host) Xfree(host);
421433

422434
goto bad;
423435
}
424436
else if (strcasecmp(name, "port") == 0)
425437
{
426438
idisplay = atoi(value);
427439

440+
if (pdpynum) XFree(pdpynum);
428441
pdpynum = copystring(value, strlen(value));
429442

430-
if (!pdpynum) goto bad;
431-
443+
if (!pdpynum)
444+
{
445+
if (host) Xfree(host);
446+
goto bad;
447+
}
432448
break;
433449
}
434450

435451
name = strtok(NULL, "=");
436452
}
437453

438-
Xfree(host);
454+
if (host) Xfree(host);
439455

440456
if (idisplay == -1)
441457
{
@@ -486,6 +502,7 @@ _X11TransConnectDisplay (
486502

487503
if (pprotocol && !strcasecmp(pprotocol, "nx"))
488504
{
505+
Xfree(pprotocol);
489506
pprotocol = copystring ("local", 5);
490507

491508
if (!pprotocol) goto bad;
@@ -502,18 +519,18 @@ _X11TransConnectDisplay (
502519
if (!pprotocol) {
503520
#if defined(UNIXCONN)
504521
if (phostname && (strcmp (phostname, "unix") == 0)) {
505-
Xfree(pprotocol);
506522
pprotocol = copystring ("unix", 4);
507523
} else
508524
#endif
509525
#ifdef HAVE_LAUNCHD
510526
if (phostname && phostname[0]=='/') {
511-
pprotocol = copystring ("local", 5);
527+
pprotocol = copystring ("local", 5);
512528
}
513529
#endif
514530
if (!phostname)
515531
{
516532
if (local_transport[0] != NULL) {
533+
if (pprotocol) Xfree(pprotocol);
517534
pprotocol = Xstrdup(local_transport[0]);
518535
local_transport_index = 0;
519536
}
@@ -611,7 +628,7 @@ _X11TransConnectDisplay (
611628
}
612629

613630
#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
614-
fprintf(stderr, "_X11TransConnectDisplay: Out of connection loop.\n");
631+
fprintf(stderr, "_X11TransConnectDisplay: Out of connection loop.\n");
615632
#endif
616633
if (address != addrbuf) Xfree (address);
617634
address = addrbuf;
@@ -636,7 +653,7 @@ _X11TransConnectDisplay (
636653
* XDisplayString() and XDisplayName() agree.
637654
*/
638655
if (reset_hostname && (phostname != original_hostname)) {
639-
Xfree (phostname);
656+
if (phostname) Xfree (phostname);
640657
phostname = original_hostname;
641658
original_hostname = NULL;
642659
}
@@ -668,7 +685,6 @@ _X11TransConnectDisplay (
668685
#if defined(LOCALCONN) || defined(UNIXCONN) || defined(TCPCONN)
669686
if (original_hostname) Xfree (original_hostname);
670687
#endif
671-
672688
GetAuthorization(trans_conn, family, (char *) saddr, saddrlen, idisplay,
673689
auth_namep, auth_namelenp, auth_datap, auth_datalenp);
674690
return trans_conn;

0 commit comments

Comments
 (0)