From 6d522c9c1dae070f73aae1022b09b68f9153959e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 29 May 2000 23:07:22 +0000 Subject: [PATCH] made getenv() more threadsafe for win32 --- lib/getenv.c | 5 +++-- lib/netrc.c | 9 ++++++++- lib/progress.c | 8 ++++++-- lib/url.c | 9 +++++++++ lib/urldata.h | 21 +++++++++++---------- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lib/getenv.c b/lib/getenv.c index 54b0118b6..ff6f541b6 100644 --- a/lib/getenv.c +++ b/lib/getenv.c @@ -39,6 +39,7 @@ #include #include +#include #ifdef WIN32 #include @@ -48,7 +49,7 @@ char *GetEnv(char *variable) { #ifdef WIN32 /* This shit requires windows.h (HUGE) to be included */ - static char env[MAX_PATH]; /* MAX_PATH is from windef.h */ + char env[MAX_PATH]; /* MAX_PATH is from windef.h */ char *temp = getenv(variable); env[0] = '\0'; ExpandEnvironmentStrings(temp, env, sizeof(env)); @@ -56,7 +57,7 @@ char *GetEnv(char *variable) /* no length control */ char *env = getenv(variable); #endif - return env; + return env?strdup(env):NULL; } char *curl_GetEnv(char *v) diff --git a/lib/netrc.c b/lib/netrc.c index 73d94ab77..bc1cc3b31 100644 --- a/lib/netrc.c +++ b/lib/netrc.c @@ -95,9 +95,14 @@ int ParseNetrc(char *host, #define NETRC DOT_CHAR "netrc" - if(!home || (strlen(home)>(sizeof(netrcbuffer)-strlen(NETRC)))) + if(!home) return -1; + if(strlen(home)>(sizeof(netrcbuffer)-strlen(NETRC))) { + free(home); + return -1; + } + sprintf(netrcbuffer, "%s%s%s", home, DIR_CHAR, NETRC); file = fopen(netrcbuffer, "r"); @@ -162,6 +167,8 @@ int ParseNetrc(char *host, fclose(file); } + free(home); + return retcode; } diff --git a/lib/progress.c b/lib/progress.c index 35847fab4..b2372aa53 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -387,6 +387,7 @@ void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/) /* 20000318 mgs */ int scr_size [2]; #endif + char *colp; if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) return; @@ -399,8 +400,11 @@ void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/) /* 20000318 mgs * OS/2 users most likely won't have this env var set, and besides that * we're using our own way to determine screen width */ - if (curl_GetEnv("COLUMNS") != NULL) - width = atoi(curl_GetEnv("COLUMNS")); + colp = curl_GetEnv("COLUMNS"); + if (colp != NULL) { + width = atoi(colp); + free(colp); + } else width = 79; #else diff --git a/lib/url.c b/lib/url.c index 5dd33a59d..8c48d0512 100644 --- a/lib/url.c +++ b/lib/url.c @@ -172,6 +172,12 @@ void urlfree(struct UrlData *data, bool totally) data->firstsocket=-1; } + if(data->bits.proxystringalloc) { + data->bits.proxystringalloc=0; + free(data->proxy); + data->proxy=NULL; + } + if(data->ptr_proxyuserpwd) { free(data->ptr_proxyuserpwd); @@ -815,10 +821,13 @@ CURLcode curl_connect(CURL *curl, CURLconnect **in_connect) if(proxy && *proxy) { /* we have a proxy here to set */ data->proxy = proxy; + data->bits.proxystringalloc=1; /* this needs to be freed later */ data->bits.httpproxy=1; } } /* if (!nope) - it wasn't specfied non-proxy */ } /* NO_PROXY wasn't specified or '*' */ + if(no_proxy) + free(no_proxy); } /* if not using proxy */ if((conn->protocol&PROT_MISSING) && data->bits.httpproxy ) { diff --git a/lib/urldata.h b/lib/urldata.h index 9960f6e70..5af199c2e 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -240,26 +240,27 @@ struct FTP { struct Configbits { bool ftp_append; bool ftp_ascii; - bool http_post; - bool http_set_referer; + bool ftp_list_only; + bool ftp_use_port; + bool hide_progress; bool http_fail_on_error; + bool http_follow_location; bool http_formpost; bool http_include_header; - bool http_follow_location; + bool http_post; bool http_put; + bool http_set_referer; + bool httpproxy; + bool mute; bool no_body; - bool ftp_list_only; - bool use_netrc; - bool ftp_use_port; + bool proxy_user_passwd; + bool proxystringalloc; /* the http proxy string is malloc()'ed */ bool set_port; bool set_range; - bool mute; - bool hide_progress; bool upload; + bool use_netrc; bool user_passwd; - bool proxy_user_passwd; bool verbose; - bool httpproxy; }; typedef size_t (*progress_callback)(void *clientp,