The FTP connection caching needs a better interface -- connections are

closed through _fetch_close() which is the only one who knows the connection
REALLY was closed (since ref -> 0).  However, FTP keeps its own local
cached_connection and checks if it is valid by comparing it to NULL.  This
is bogus since it may have been freed elsewhere by _fetch_close().

This change checks if we are closing the cached_connection and the ref is 1
(soon to be 0).  If so, set cached_connection to NULL so we don't
accidentally reuse it.  The REAL fix should be to move connection caching
to the common.c level (_fetch_* functions) and NULL the cache(s) in
_fetch_close().  Then all layers could benefit from caching.
This commit is contained in:
Nate Lawson 2002-10-25 01:17:32 +00:00
parent 9ab73fd11a
commit 13cc1c8394
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=105903

View File

@ -419,6 +419,8 @@ _ftp_closefn(void *v)
io->dconn = NULL;
DEBUG(fprintf(stderr, "Waiting for final status\n"));
r = _ftp_chkerr(io->cconn);
if (io->cconn == cached_connection && io->cconn->ref == 1)
cached_connection = NULL;
_fetch_close(io->cconn);
free(io);
return (r == FTP_TRANSFER_COMPLETE) ? 0 : -1;
@ -833,6 +835,8 @@ static void
_ftp_disconnect(conn_t *conn)
{
(void)_ftp_cmd(conn, "QUIT");
if (conn == cached_connection && conn->ref == 1)
cached_connection = NULL;
_fetch_close(conn);
}