serkos
serkos

Reputation: 314

Using curl_easy_init in the constructor leads to segfault

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

Answers (1)

Zack Kaytranada
Zack Kaytranada

Reputation: 361

the variable is losing it's scope. Check the value of curl variable when it enters in GetPage function.

Upvotes: 2

Related Questions