aboutsummaryrefslogtreecommitdiff
path: root/lib/file.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2007-10-22 15:05:35 +0000
committerDaniel Stenberg <daniel@haxx.se>2007-10-22 15:05:35 +0000
commit5b358603bd8897dcd38795c1ae971a8f917e97df (patch)
tree2832440bbb6bfa0e7d597707ec02e8e80d73d794 /lib/file.c
parent3910a61b617ed3f943f1f2bc25b3f034a82f692d (diff)
Michal Marek forwarded the bug report
https://bugzilla.novell.com/show_bug.cgi?id=332917 about a HTTP redirect to FTP that caused memory havoc. His work together with my efforts created two fixes: #1 - FTP::file was moved to struct ftp_conn, because is has to be dealt with at connection cleanup, at which time the struct HandleData could be used by another connection. Also, the unused char *urlpath member is removed from struct FTP. #2 - provide a Curl_reset_reqproto() function that frees data->reqdata.proto.* on connection setup if needed (that is if the SessionHandle was used by a different connection).
Diffstat (limited to 'lib/file.c')
-rw-r--r--lib/file.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/file.c b/lib/file.c
index 6d4ae9892..bce92bd2a 100644
--- a/lib/file.c
+++ b/lib/file.c
@@ -125,8 +125,8 @@ const struct Curl_handler Curl_handler_file = {
*/
CURLcode Curl_file_connect(struct connectdata *conn)
{
- char *real_path = curl_easy_unescape(conn->data, conn->data->reqdata.path, 0,
- NULL);
+ struct SessionHandle *data = conn->data;
+ char *real_path = curl_easy_unescape(data, data->reqdata.path, 0, NULL);
struct FILEPROTO *file;
int fd;
#if defined(WIN32) || defined(MSDOS) || defined(__EMX__)
@@ -137,16 +137,18 @@ CURLcode Curl_file_connect(struct connectdata *conn)
if(!real_path)
return CURLE_OUT_OF_MEMORY;
- file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1);
- if(!file) {
- free(real_path);
- return CURLE_OUT_OF_MEMORY;
- }
-
- if (conn->data->reqdata.proto.file)
- free(conn->data->reqdata.proto.file);
+ /* If there already is a protocol-specific struct allocated for this
+ sessionhandle, deal with it */
+ Curl_reset_reqproto(conn);
- conn->data->reqdata.proto.file = file;
+ if (!data->reqdata.proto.file) {
+ file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1);
+ if(!file) {
+ free(real_path);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ data->reqdata.proto.file = file;
+ }
#if defined(WIN32) || defined(MSDOS) || defined(__EMX__)
/* If the first character is a slash, and there's
@@ -186,8 +188,8 @@ CURLcode Curl_file_connect(struct connectdata *conn)
file->freepath = real_path; /* free this when done */
file->fd = fd;
- if(!conn->data->set.upload && (fd == -1)) {
- failf(conn->data, "Couldn't open file %s", conn->data->reqdata.path);
+ if(!data->set.upload && (fd == -1)) {
+ failf(data, "Couldn't open file %s", data->reqdata.path);
Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE);
return CURLE_FILE_COULDNT_READ_FILE;
}