summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1996-06-17 20:36:57 +0000
committerjkh <jkh@FreeBSD.org>1996-06-17 20:36:57 +0000
commit257dcecd299fb32452b70b4e78fcd722579e97d0 (patch)
tree3045c33081e766e2acc9453820cffe77982f1414 /lib
parent0f0df70b6f18b352556b9294422b310323041524 (diff)
downloadFreeBSD-src-257dcecd299fb32452b70b4e78fcd722579e97d0.zip
FreeBSD-src-257dcecd299fb32452b70b4e78fcd722579e97d0.tar.gz
Stamp out a potential memory leak.
Make ftpChdir return the server status again - it was more convenient.
Diffstat (limited to 'lib')
-rw-r--r--lib/libftpio/ftpio.32
-rw-r--r--lib/libftpio/ftpio.c25
2 files changed, 17 insertions, 10 deletions
diff --git a/lib/libftpio/ftpio.3 b/lib/libftpio/ftpio.3
index 69700c0..db8def2 100644
--- a/lib/libftpio/ftpio.3
+++ b/lib/libftpio/ftpio.3
@@ -84,7 +84,7 @@ will return the error code returned by the foreign server.
.Fn ftpChdir
attempts to issue a server CD command to the the directory named in
.Fa dir.
-On success, zero is returned. On failure, -1.
+On success, zero is returned. On failure, the error code from the server.
.Pp
.Fn ftpErrno
returns the server failure code for the last operation (useful for seeing
diff --git a/lib/libftpio/ftpio.c b/lib/libftpio/ftpio.c
index 6f74318..6420bb0 100644
--- a/lib/libftpio/ftpio.c
+++ b/lib/libftpio/ftpio.c
@@ -14,7 +14,7 @@
* Turned inside out. Now returns xfers as new file ids, not as a special
* `state' of FTP_t
*
- * $Id: ftpio.c,v 1.2 1996/06/17 12:42:33 jkh Exp $
+ * $Id: ftpio.c,v 1.3 1996/06/17 15:28:00 jkh Exp $
*
*/
@@ -122,11 +122,8 @@ ftpLogin(char *host, char *user, char *passwd, int port)
fp = NULL;
if (n && ftp_login_session(n, host, user, passwd, port) == SUCCESS) {
fp = funopen(n, ftp_read_method, ftp_write_method, NULL, ftp_close_method); /* BSD 4.4 function! */
- /* Yuck, but can't use fdopen() because that also allocates an fp. Sigh! */
fp->_file = n->fd_ctrl;
}
- if (n && !fp)
- free(n);
return fp;
}
@@ -138,7 +135,7 @@ ftpChdir(FILE *fp, char *dir)
i = cmd(ftp, "CWD %s", dir);
if (i < 0 || check_code(ftp, i, FTP_CHDIR_HAPPY))
- return -1;
+ return i;
return SUCCESS;
}
@@ -347,7 +344,11 @@ ftp_write_method(void *vp, const char *buf, int nbytes)
static int
ftp_close_method(void *n)
{
- return ftp_close((FTP_t)n);
+ int i;
+
+ i = ftp_close((FTP_t)n);
+ free(n);
+ return i;
}
static void
@@ -411,8 +412,10 @@ get_a_number(FTP_t ftp, char **q)
while(1) {
p = get_a_line(ftp);
- if (!p)
+ if (!p) {
+ ftp_close(ftp);
return FAILURE;
+ }
if (!(isdigit(p[0]) && isdigit(p[1]) && isdigit(p[2])))
continue;
if (i == -1 && p[3] == '-') {
@@ -497,8 +500,10 @@ ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port)
if (networkInit() != SUCCESS)
return FAILURE;
- if (ftp->con_state != init)
+ if (ftp->con_state != init) {
ftp_close(ftp);
+ return FAILURE;
+ }
if (!user)
user = "ftp";
@@ -578,8 +583,10 @@ ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, int *
return FAILURE;
}
i = get_a_number(ftp, &q);
- if (check_code(ftp, i, FTP_PASSIVE_HAPPY))
+ if (check_code(ftp, i, FTP_PASSIVE_HAPPY)) {
+ ftp_close(ftp);
return i;
+ }
while (*q && !isdigit(*q))
q++;
if (!*q) {
OpenPOWER on IntegriCloud