Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:marvin24
curl
reset-reqproto.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File reset-reqproto.patch of Package curl
Based on Daniel's patch, 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). --- lib/file.c | 28 +++++++++++++++------------- lib/ftp.c | 10 +++++----- lib/http.c | 7 +++++-- lib/ssh.c | 4 ++++ lib/url.c | 16 ++++++++++++++++ lib/url.h | 5 +++++ lib/urldata.h | 2 ++ 7 files changed, 52 insertions(+), 20 deletions(-) --- lib/file.c.orig +++ lib/file.c @@ -96,7 +96,8 @@ */ 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__) @@ -107,18 +108,19 @@ CURLcode Curl_file_connect(struct connec 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); + + 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; } - conn->data->reqdata.proto.file = file; - #if defined(WIN32) || defined(MSDOS) || defined(__EMX__) /* If the first character is a slash, and there's something that looks like a drive at the beginning of @@ -157,8 +159,8 @@ CURLcode Curl_file_connect(struct connec 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; } --- lib/ftp.c.orig +++ lib/ftp.c @@ -90,6 +90,7 @@ #include "parsedate.h" /* for the week day and month names */ #include "sockaddr.h" /* required for Curl_sockaddr_storage */ #include "multiif.h" +#include "url.h" #if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL) #include "inet_ntoa_r.h" @@ -2953,11 +2954,9 @@ CURLcode Curl_ftp_connect(struct connect *done = FALSE; /* default to not done yet */ - if (data->reqdata.proto.ftp) { - Curl_ftp_disconnect(conn); - free(data->reqdata.proto.ftp); - data->reqdata.proto.ftp = NULL; - } + /* If there already is a protocol-specific struct allocated for this + sessionhandle, deal with it */ + Curl_reset_reqproto(conn); result = ftp_init(conn); if(result) @@ -3487,6 +3486,7 @@ CURLcode Curl_ftp(struct connectdata *co make sure we have a good 'struct FTP' to play with. For new connections, the struct FTP is allocated and setup in the Curl_ftp_connect() function. */ + Curl_reset_reqproto(conn); retcode = ftp_init(conn); if(retcode) return retcode; --- lib/http.c.orig +++ lib/http.c @@ -1734,13 +1734,16 @@ CURLcode Curl_http(struct connectdata *c the rest of the request in the PERFORM phase. */ *done = TRUE; + /* If there already is a protocol-specific struct allocated for this + sessionhandle, deal with it */ + Curl_reset_reqproto(conn); + if(!data->reqdata.proto.http) { /* Only allocate this struct if we don't already have it! */ - http = (struct HTTP *)malloc(sizeof(struct HTTP)); + http = (struct HTTP *)calloc(sizeof(struct HTTP), 1); if(!http) return CURLE_OUT_OF_MEMORY; - memset(http, 0, sizeof(struct HTTP)); data->reqdata.proto.http = http; } else --- lib/ssh.c.orig +++ lib/ssh.c @@ -824,6 +824,10 @@ CURLcode Curl_ssh_connect(struct connect CURLcode result; struct SessionHandle *data = conn->data; + /* If there already is a protocol-specific struct allocated for this + sessionhandle, deal with it */ + Curl_reset_reqproto(conn); + result = ssh_init(conn); if (result) return result; --- lib/url.c.orig +++ lib/url.c @@ -1793,6 +1793,9 @@ static void conn_free(struct connectdata if(CURL_SOCKET_BAD != conn->sock[FIRSTSOCKET]) sclose(conn->sock[FIRSTSOCKET]); + if (conn->data->reqdata.current_conn == conn) { + conn->data->reqdata.current_conn = NULL; + } Curl_safefree(conn->user); Curl_safefree(conn->passwd); Curl_safefree(conn->proxyuser); @@ -4362,3 +4365,16 @@ CURLcode Curl_do_more(struct connectdata return result; } + +/* Called on connect, and if there's already a protocol-specific struct + allocated for a different connection, this frees it that it can be setup + properly later on. */ +void Curl_reset_reqproto(struct connectdata *conn) +{ + struct SessionHandle *data = conn->data; + if (data->reqdata.proto.generic && data->reqdata.current_conn != conn) { + free(data->reqdata.proto.generic); + data->reqdata.proto.generic = NULL; + } + data->reqdata.current_conn = conn; +} --- lib/url.h.orig +++ lib/url.h @@ -82,4 +82,9 @@ CURLcode Curl_doing_fdset(struct connect int *max_fdp); #endif +/* Called on connect, and if there's already a protocol-specific struct + allocated for a different connection, this frees it that it can be setup + properly later on. */ +void Curl_reset_reqproto(struct connectdata *conn); + #endif --- lib/urldata.h.orig +++ lib/urldata.h @@ -736,6 +736,8 @@ struct HandleData { void *generic; struct SSHPROTO *ssh; } proto; + /* current user of this HandleData instance, or NULL */ + struct connectdata *current_conn; }; /*
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor