vncv: fix netmkvncaddr()

netmkaddr() can return a the pointer to the host string if
it is already a full dial string. but we assumed to get
a copy and freed it before returning.
This commit is contained in:
cinap_lenrek 2016-05-05 02:11:00 +02:00
parent c7db24fc26
commit 5a2ad90bec

View file

@ -43,14 +43,11 @@ shutdown(void)
} }
char* char*
netmkvncaddr(char *inserver) netmkvncaddr(char *server)
{ {
char *p, portstr[NETPATHLEN], *server; char *p, portstr[NETPATHLEN];
int port; int port;
server = strdup(inserver);
assert(server != nil);
port = 5900; port = 5900;
if(tls) if(tls)
port = 35729; port = 35729;
@ -58,11 +55,8 @@ netmkvncaddr(char *inserver)
*p++ = '\0'; *p++ = '\0';
port += atoi(p); port += atoi(p);
} }
snprint(portstr, sizeof portstr, "%d", port); snprint(portstr, sizeof portstr, "%d", port);
p = netmkaddr(server, "tcp", portstr); return netmkaddr(server, "tcp", portstr);
free(server);
return p;
} }
void void
@ -82,7 +76,7 @@ void
main(int argc, char **argv) main(int argc, char **argv)
{ {
int p, dfd, cfd, shared; int p, dfd, cfd, shared;
char *keypattern, *addr, *label; char *keypattern, *label;
Point d; Point d;
keypattern = nil; keypattern = nil;
@ -116,11 +110,10 @@ main(int argc, char **argv)
if(argc != 1) if(argc != 1)
usage(); usage();
addr = netmkvncaddr(argv[0]); serveraddr = strdup(argv[0]);
serveraddr = argv[0]; dfd = dial(netmkvncaddr(argv[0]), nil, nil, &cfd);
dfd = dial(addr, nil, nil, &cfd);
if(dfd < 0) if(dfd < 0)
sysfatal("cannot dial %s: %r", addr); sysfatal("cannot dial %s: %r", serveraddr);
if(tls){ if(tls){
TLSconn conn; TLSconn conn;