about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMikael Magnusson <mikachu@gmail.com>2014-11-23 21:43:25 +0100
committerMikael Magnusson <mikachu@gmail.com>2014-11-24 08:16:48 +0100
commite2fe81ae9ab6e3fafa0b5b190a529193c1df91b0 (patch)
treeb1be9cebc205cc5edac2972bca4d232caabc2167
parent2b615bedaff1d64a1521972717a91058c74b579f (diff)
downloadzsh-e2fe81ae9ab6e3fafa0b5b190a529193c1df91b0.tar.gz
zsh-e2fe81ae9ab6e3fafa0b5b190a529193c1df91b0.tar.xz
zsh-e2fe81ae9ab6e3fafa0b5b190a529193c1df91b0.zip
33785: Fix leaks of desthost in ztcp
Found by coverity.
-rw-r--r--ChangeLog4
-rw-r--r--Src/Modules/tcp.c4
2 files changed, 8 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index d59c99290..009d65195 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2014-11-24  Mikael Magnusson  <mikachu@gmail.com>
+
+	* 33785: Src/Modules/tcp.c: Fix leaks of desthost in ztcp.
+
 2014-11-23  Barton E. Schaefer  <schaefer@zsh.org>
 
 	* 33775: Src/exec.c: error opening file in $(<...) is not fatal
diff --git a/Src/Modules/tcp.c b/Src/Modules/tcp.c
index 3f92050ae..0d9522047 100644
--- a/Src/Modules/tcp.c
+++ b/Src/Modules/tcp.c
@@ -623,6 +623,7 @@ bin_ztcp(char *nam, char **args, Options ops, UNUSED(int func))
 	zthost = zsh_getipnodebyname(desthost, AF_INET, 0, &herrno);
 	if (!zthost || errflag) {
 	    zwarnnam(nam, "host resolution failure: %s", desthost);
+	    zsfree(desthost);
 	    return 1;
 	}
 	
@@ -630,6 +631,7 @@ bin_ztcp(char *nam, char **args, Options ops, UNUSED(int func))
 
 	if (!sess) {
 	    zwarnnam(nam, "unable to allocate a TCP session slot");
+	    zsfree(desthost);
 	    return 1;
 	}
 
@@ -665,6 +667,8 @@ bin_ztcp(char *nam, char **args, Options ops, UNUSED(int func))
 		sess->fd = redup(sess->fd, targetfd);
 		if (sess->fd < 0) {
 		    zerrnam(nam, "could not duplicate socket fd to %d: %e", targetfd, errno);
+		    zsfree(desthost);
+		    tcp_close(sess);
 		    return 1;
 		}
 	    }