cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Dangling Pointers

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Mon, 21 May 2001 08:45:51 +0200 (MET DST)

On Sun, 20 May 2001, Ryan Earl wrote:

> However... I've been playing with it for quite some time and have run
> into runtime errors all over the place dealing with curl simply not
> copying over specified data to internal curl data structures.

Well, libcurl has quite a simple policy in this aspect: it never copies the
data. Unless it really has to.

> It would be nice if the documentation was more specific about how long I
> have to keep around memory I use for curl arguments for all
> functions/options.

That is of course a very good idea. I need patches and help with the
documentation as much as I need help with the code...

> ie mention that I -don't- have to keep my copy around, etc. For
> instance, in curl_easy_setopt, CURLOPT_HTTPPOST doesn't mention you have
> to keep the post field list around until after you call
> curl_easy_perform.

In the particular case of CURLOPT_HTTPPOST, you normally build the list
passed there with curl_formparse() and that is one of the few functions in
libcurl that actually do strdup() the input data.

> I ended up moving -all- arguments off the stack just trying to get this
> to run, but I still am running into a weird error. With my debug build,
> the program behaves well. It does a POST with all the correct data.
> However, with a release build, everytime I get a memory access violation
> error in curl_easy_perform.

Ugha. Those kinds of problems are certainly painful to debug.

> Without debugging symbols, it's pain to figure out what this is. Had to
> resort to "printf" methodolgy just to find the function where it died.
> Can anyone spot anything wrong in this code? (yea, it's ugly)

No, I'm afraid I can't readily detect any obvious major error in your usage
of the lib. Except for a tiny little detail that might just be your problem:

> // curl_easy_setopt( pCURL, CURLOPT_WRITEFUNCTION, logOutput );
> curl_easy_setopt( pCURL, CURLOPT_FILE, m_logFile );

Win32 has some very interesting "border restrictions" between DLLs and
"normal" programs (that most(?) unix systems don't). Like you can't pass
FILE pointers between them. In the above two lines, you pass your program's
FILE pointer to the DLLs write function, which it won't like. No, I can't
explain why that works in the debug version!

Try passing your own write function as well, and it'll probably succeed. Do
notice that you need to make that callback function an extern "C" thing, as
it won't be called as a C++ function.

A separate note (which has nothing to do with the access violation) might be
that judging from the looks of your program, CURLOPT_HTTPPOST might not be
want you want. You might want CURLOPT_POST.

-- 
     Daniel Stenberg -- curl dude -- http://curl.haxx.se/
_______________________________________________
Curl-library mailing list
Curl-library_at_lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/curl-library
Received on 2001-05-21