summaryrefslogtreecommitdiffstats
path: root/sftp-client.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2018-07-31 05:07:24 +0200
committerDamien Miller <djm@mindrot.org>2018-07-31 05:13:26 +0200
commit1a66079c0669813306cc69e5776a4acd9fb49015 (patch)
tree892eb2fcddac9189cc1d8e7a9b821bde27ba1014 /sftp-client.c
parentRemove support for S/Key (diff)
downloadopenssh-1a66079c0669813306cc69e5776a4acd9fb49015.tar.xz
openssh-1a66079c0669813306cc69e5776a4acd9fb49015.zip
upstream: fix some memory leaks spotted by Coverity via Jakub Jelen
in bz#2366 feedback and ok dtucker@ OpenBSD-Commit-ID: 8402bbae67d578bedbadb0ce68ff7c5a136ef563
Diffstat (limited to 'sftp-client.c')
-rw-r--r--sftp-client.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/sftp-client.c b/sftp-client.c
index dc4d8c4e0..4986d6d8d 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-client.c,v 1.129 2018/05/25 04:25:46 djm Exp $ */
+/* $OpenBSD: sftp-client.c,v 1.130 2018/07/31 03:07:24 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -1461,7 +1461,7 @@ download_dir_internal(struct sftp_conn *conn, const char *src, const char *dst,
{
int i, ret = 0;
SFTP_DIRENT **dir_entries;
- char *filename, *new_src, *new_dst;
+ char *filename, *new_src = NULL, *new_dst = NULL;
mode_t mode = 0777;
if (depth >= MAX_DIR_DEPTH) {
@@ -1499,8 +1499,10 @@ download_dir_internal(struct sftp_conn *conn, const char *src, const char *dst,
}
for (i = 0; dir_entries[i] != NULL && !interrupted; i++) {
- filename = dir_entries[i]->filename;
+ free(new_dst);
+ free(new_src);
+ filename = dir_entries[i]->filename;
new_dst = path_append(dst, filename);
new_src = path_append(src, filename);
@@ -1523,9 +1525,9 @@ download_dir_internal(struct sftp_conn *conn, const char *src, const char *dst,
} else
logit("%s: not a regular file\n", new_src);
- free(new_dst);
- free(new_src);
}
+ free(new_dst);
+ free(new_src);
if (preserve_flag) {
if (dirattrib->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
@@ -1793,7 +1795,7 @@ upload_dir_internal(struct sftp_conn *conn, const char *src, const char *dst,
int ret = 0;
DIR *dirp;
struct dirent *dp;
- char *filename, *new_src, *new_dst;
+ char *filename, *new_src = NULL, *new_dst = NULL;
struct stat sb;
Attrib a, *dirattrib;
@@ -1844,6 +1846,8 @@ upload_dir_internal(struct sftp_conn *conn, const char *src, const char *dst,
while (((dp = readdir(dirp)) != NULL) && !interrupted) {
if (dp->d_ino == 0)
continue;
+ free(new_dst);
+ free(new_src);
filename = dp->d_name;
new_dst = path_append(dst, filename);
new_src = path_append(src, filename);
@@ -1870,9 +1874,9 @@ upload_dir_internal(struct sftp_conn *conn, const char *src, const char *dst,
}
} else
logit("%s: not a regular file\n", filename);
- free(new_dst);
- free(new_src);
}
+ free(new_dst);
+ free(new_src);
do_setstat(conn, dst, &a);