cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Curl Multi Problem.

From: Richard Atterer <richard_at_2007.atterer.net>
Date: Mon, 6 Aug 2007 11:25:34 +0200

On Mon, Aug 06, 2007 at 01:32:16PM +0530, Surya Kiran Gullapalli wrote:
> ostringstream os ;
> os << "http://curl.haxx.se" ;
> curl_easy_setopt(http_handle, CURLOPT_URL,
> os.str().c_str()) ;

The docs for CURLOPT_URL say: "The string must remain present until curl no
longer needs it, as it doesn't copy the string."

However, when you call os.str(), a temporary string object is created by
the C++ compiler, and c_str() returns a pointer to its contents. Once the
curl_easy_setopt() call returns, the temporary object is destroyed, so you
are left with a dangling pointer to the URL.

Cheers,

  Richard

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