cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: init in a different function

From: Fredrik Gustafsson <iveqy.mailbox_at_gmail.com>
Date: Fri, 17 Mar 2006 07:42:39 +0100

Thank you,
a cpp user that I am I tried with referens instead. And it worked, the
program won't shut down anymore. But now there is a new problem.

It seems like my program is using different CURLs, because that session
handling for the homepage don't work. If I put it all in the same
function it works fine...

int main
{
    CURL * curl;
    init_c(curl);
    login_page(curl);
    load_page(curl);
    return 0;
}

void init_c(CURL *& curl)
{
    curl = curl_easy_init();
}

void login_page(CURL *& curl)
{
    curl_easy_perform......
}

void load_page(CURL *& curl)
{
    curl_easy_perform......
}

It's like login_page() and load_page() doesn't get the same CURL *.

On Thu, Mar 16, 2006 at 01:28:15PM -0800, Dan Fandrich wrote:
> On Thu, Mar 16, 2006 at 08:41:13PM +0100, Fredrik Gustafsson wrote:
> > this code gives me segment fault (in short):
> >
> > int main()
> > {
> > CURL * curl;
> > init_c(curl);
> > return 0;
> > }
> >
> > void init_c(CURL * curl)
> > {
> > curl = curl_easy_init();
> > }
> >
> > I don't get it. If I put the line "curl = curl_easy_init()" in main() it
> > works fine...
>
> That code is wrong, but I'm a bit surprised this causes a segfault if this
> is all there is. What it looks like you're trying to do is get init_c
> to pass back a curl handle. You need to pass in the pointer to the CURL
> pointer to do that, like this: init_c(&curl) and store the handle like:
> *curl = curl_easy_init();
> and modify the init_c declaration to take CURL** curl.
>
> >>> Dan
> --
> http://www.MoveAnnouncer.com The web change of address service
> Let webmasters know that your web site has moved
Received on 2006-03-17