cURL / Mailing Lists / curl-users / Single Mail

curl-users

lib cURL instability and stack/stream-related crashes in easy_perform

From: John Chamberlain <jsc_at_johnchamberlain.com>
Date: Sun, 19 Dec 2004 13:37:52 -0500

I am experiencing crashes in easy_perform.

operating system: Windows 2000 sp4
unix sub-environment: MSys 1.0.10
compiler: gcc (GCC) 3.2.3 (mingw special 20030504-1)
lib curl: 7.12.1

The following shows the problem situation:

******** WORKS A: ********************************************

void function_1(){
     char* sURL = "http://www.cnn.com";
     do_curl_stuff( sURL ); /* easy perform in here */
}

******** DOES NOT WORK B (crashes inside easy_perform): ***************

void function_1(){
     char* sURL = "http://www.cnn.com";
     function_2( sURL );
}

void function_2( char *sURL ){
   do_curl_stuff( sURL ); /* easy perform in here */
}

******** WORKS C: ***************

void function_1(){
     char* sURL = "http://www.cnn.com";
     function_2( sURL );
}

void function_2( char *sURL ){
   random_actions(0);
   do_curl_stuff( sURL ); /* easy perform in here */
}

/* this function appears to do nothing, none of these variables are used
in any way */
void random_actions(int a){ /* all statements must be present even
though they do nothing */
   int x;
   int y;
   int z;
   char* q = malloc(100); /* if this statement is done first, program
crashes */
}

******** WORKS D: ***************
- call fflush(stdout) before calling easy_perform

Discussion:

The above shows the problem in skeletal form. The program I am writing
using lib cURL allows the user to type an url to a command line prompt
and then returns the html text to the screen. The prompt, the output and
various debugging messages are written to stdout.

 From the above cases A and B you can see how I came across the problem.
I had code that was working perfectly fine, but when I added an
additional level of call cURL started crashing inside easy_perform.
After extensive experimentation I found that if I called the function
random_actions before beginning the curl operations for some reason it
would not crash. This is mysterious because this function does
absolutely nothing other than declare some local variables (which are
never used) and do a malloc. For example, with everything exactly the
same if I delete only the declaration "int y" (which is never used) that
is enough to be the difference between easy_perform crashing and not
crashing. It is repeatable.

After additional experimentation I found that I could alternatively get
easy_perfom to not crash if I called fflush(stdout) immediately before
calling easy_perform.

Obviously this problem is some low-level thing possibly having to do
with the compiler, with threading or with the operating system.

Any ideas?

Regards, John Chamberlain
Received on 2004-12-19