diff options
author | Igor Böhm <boehm.igor@gmail.com> | 2020-07-22 20:59:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-22 14:59:58 -0400 |
commit | afa34a73a91655f16d24abae491881ae45500d78 (patch) | |
tree | 9839182a777e82b3e9cacd4a32c1c31480e9a380 /src | |
parent | 057d8a76a9d840994edf453f97245efb295d9582 (diff) | |
download | plan9port-afa34a73a91655f16d24abae491881ae45500d78.tar.gz plan9port-afa34a73a91655f16d24abae491881ae45500d78.tar.bz2 plan9port-afa34a73a91655f16d24abae491881ae45500d78.zip |
devdraw, libdraw: fix memory leaks by freeing getns() malloced string (#431)
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/devdraw/srv.c | 8 | ||||
-rw-r--r-- | src/libdraw/drawclient.c | 7 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/cmd/devdraw/srv.c b/src/cmd/devdraw/srv.c index 05a08fda..479e41e0 100644 --- a/src/cmd/devdraw/srv.c +++ b/src/cmd/devdraw/srv.c @@ -88,7 +88,7 @@ threadmain(int argc, char **argv) void gfx_started(void) { - char *addr; + char *ns, *addr; if(srvname == nil) { // Legacy mode: serving single client on pipes. @@ -97,7 +97,11 @@ gfx_started(void) } // Server mode. - addr = smprint("unix!%s/%s", getns(), srvname); + if((ns = getns()) == nil) + sysfatal("out of memory"); + + addr = smprint("unix!%s/%s", ns, srvname); + free(ns); if(addr == nil) sysfatal("out of memory"); diff --git a/src/libdraw/drawclient.c b/src/libdraw/drawclient.c index c38f4801..2ac1b232 100644 --- a/src/libdraw/drawclient.c +++ b/src/libdraw/drawclient.c @@ -23,7 +23,7 @@ int _displayconnect(Display *d) { int pid, p[2], fd, nbuf, n; - char *wsysid, *addr, *id; + char *wsysid, *ns, *addr, *id; uchar *buf; Wsysmsg w; @@ -40,7 +40,10 @@ _displayconnect(Display *d) return -1; } *id++ = '\0'; - addr = smprint("unix!%s/%s", getns(), wsysid); + if((ns = getns()) == nil) + return -1; + addr = smprint("unix!%s/%s", ns, wsysid); + free(ns); if(addr == nil) return -1; fd = dial(addr, 0, 0, 0); |