On Sunday 08 March 2009 23:23:40 Daniel Stenberg wrote:
> On Sat, 7 Mar 2009, Kamil Dudka wrote:
> > Thanks for explanation. So the proper solution is to fix all the code
> > using libcurl to call curl_global_init() at first, starting with the curl
> > tool.
>
> Exactly!
>
> > Worth to write a patch?
>
> I'd certainly welcome one! Thanks for the offer.
Attached simple patch fixes the memory leak in curl tool by moving call
of curl_global_init() up.
Kamil
diff -ruNp curl.orig/include/curl/curl.h curl/include/curl/curl.h
--- curl.orig/include/curl/curl.h 2009-03-11 12:03:34.980111000 +0100
+++ curl/include/curl/curl.h 2009-03-11 12:04:01.451390298 +0100
@@ -1510,7 +1510,7 @@ CURL_EXTERN void curl_free(void *p);
* DESCRIPTION
*
* curl_global_init() should be invoked exactly once for each application that
- * uses libcurl
+ * uses libcurl and before any call of other libcurl function
*/
CURL_EXTERN CURLcode curl_global_init(long flags);
diff -ruNp curl.orig/src/main.c curl/src/main.c
--- curl.orig/src/main.c 2009-03-11 12:03:34.983111000 +0100
+++ curl/src/main.c 2009-03-11 12:04:01.454390330 +0100
@@ -3969,6 +3969,12 @@ operate(struct Configurable *config, int
memset(&heads, 0, sizeof(struct OutStruct));
+ /* initialize curl library - do not call any libcurl functions before */
+ if (main_init() != CURLE_OK) {
+ helpf(config->errors, "error initializing curl library\n");
+ return CURLE_FAILED_INIT;
+ }
+
#ifdef CURLDEBUG
/* this sends all memory debug messages to a logfile named memdump */
env = curlx_getenv("CURL_MEMDEBUG");
@@ -4015,10 +4021,6 @@ operate(struct Configurable *config, int
#endif
/* inits */
- if (main_init() != CURLE_OK) {
- helpf(config->errors, "error initializing curl library\n");
- return CURLE_FAILED_INIT;
- }
config->postfieldsize = -1;
config->showerror=TRUE;
config->use_httpget=FALSE;