Reputation: 314
When I wrap libcurl in class I face with problem:
Foo::Foo()
{
curl = curl_easy_init();
if (!curl)
throw std::runtime("Can't initialize libcurl");
}
char* Foo::GetPage(char *url)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, WriteData );
curl_easy_setopt( curl, CURLOPT_WRITEDATA, (void *)data);
CURLcode res = curl_easy_perform( curl );
}
I got a segfault on the first line of GetPage function (setting url). If I initalize curl in the GetPage - all is OK. Anyone else faced a similar problem?
Upvotes: 0
Views: 730
Reputation: 361
the variable is losing it's scope. Check the value of curl variable when it enters in GetPage function.
Upvotes: 2