cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_multi question

From: Richard Atterer <richard_at_2007.atterer.net>
Date: Fri, 10 Aug 2007 11:01:37 +0200

On Fri, Aug 10, 2007 at 10:00:22AM +0530, Surya Kiran Gullapalli wrote:
> 2. If this is the way to write data to files, then why the segmentation
> violation?

Because your code is buggy! Sorry, but none of the problems you post here
have a lot to do with libcurl, you should learn C++ properly. "Learning by
doing" is not possible with C++ (or even C).

> CURL* set_handle (const string& site, const string& code, int idx)
> {
> OutFile outfile ;
> outfile.filename = ("out-") ;
> outfile.filename += code ;
> outfile.fp = NULL ;
>
> files [idx] = outfile ;
>
> CURL *handle = curl_easy_init() ;
> curl_easy_setopt(handle, CURLOPT_URL, site.c_str()) ;
> curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1) ;
> /*
> curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_function) ;
> curl_easy_setopt(handle, CURLOPT_WRITEDATA, &outfile) ;
> */
> return handle ;
> }

Same problem as in your previous post: "outfile" is a function-local
variable. You create a pointer to it using
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &outfile), and then the object
is destroyed when set_handle returns. So you are left with a dangling
pointer.

Cheers,

  Richard

-- 
  __   _
  |_) /|  Richard Atterer     |  GnuPG key: 888354F7
  | \/|  http://atterer.net  |  08A9 7B7D 3D13 3EF2 3D25  D157 79E6 F6DC 8883 54F7
   '` 
Received on 2007-08-10