]> granicus.if.org Git - curl/commitdiff
made getenv() more threadsafe for win32
authorDaniel Stenberg <daniel@haxx.se>
Mon, 29 May 2000 23:07:22 +0000 (23:07 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 29 May 2000 23:07:22 +0000 (23:07 +0000)
lib/getenv.c
lib/netrc.c
lib/progress.c
lib/url.c
lib/urldata.h

index 54b0118b63971e32af754c676c594f87208f94af..ff6f541b6fca78b026d55dc794091f203b0ad43d 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #ifdef WIN32
 #include <windows.h>
@@ -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)
index 73d94ab77f5d19dcbffe1d164d05ab6c09381452..bc1cc3b31facfe946a7510e4195b33f5c60f1671 100644 (file)
@@ -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;
 }
 
index 35847fab4200edefaa8f1814fc866a929e55a5f1..b2372aa5308a4583ffbf1cdc60677605988be1c8 100644 (file)
@@ -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
index 5dd33a59d50c7d89549aa4df27ae95c2fc9101c7..8c48d05128400bb17e945434b8bf94922663cabb 100644 (file)
--- 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 ) {
index 9960f6e700392e58fd7588b3a6d0f16997a6ffc6..5af199c2e675f1126eb1eba9f0b8bd24a81b06a0 100644 (file)
@@ -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,