cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURLOPT_WRITEDATA segmentation fault

From: Lucas Ces <lucas.ces_at_gmail.com>
Date: Thu, 30 Oct 2008 17:41:02 -0200

Sorry for bother you guys. After 2 days breaking my head over this
code, just after I posted I found that a (void*) conversion of the
file when passing it to curl_easy_setopt solves the problem;

so the changed line became:

curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)image);

--
Lucas Ces
Laboratório de Tecnologia da Informação Aplicada - LTIA
Universidade Estadual Paulista, Bauru - UNESP
+55 14 3011-1596 / +55 11 8319-1327
lucas.santos_at_ltia.fc.unesp.br
www.ltia.fc.unesp.br
Best Regards
On Thu, Oct 30, 2008 at 5:20 PM, Lucas Ces <lucas.ces_at_gmail.com> wrote:
> Hi everybody, I'm writting a tiny set o classes that uses
> libflickrcurl to retrieve data from Flickr REST and libcurl to
> download the images with the URL obtained from libflickrcurl. My
> problem is that piece of code:
>
> string FlickrPhoto::getThumbnailPath()
> {
>        FILE *image;
>        char *tmp_filename;
>        //void *buff;
>
>        CURL *curl;
>        CURLcode res;
>
>        curl = curl_easy_init();
>        if (curl)
>        {
>                curl_easy_setopt(curl, CURLOPT_URL, this -> thumbnailUrl.c_str());
>
>                tmp_filename = new char[L_tmpnam+1];
>                strcpy(tmp_filename,"/tmp/thumbXXXXXX");
>                mkstemp(tmp_filename);
>                this -> thumbnailPath = (string)tmp_filename;
>
>                image = fopen(this -> thumbnailPath.c_str(),"wb");
>                curl_easy_setopt(curl, CURLOPT_WRITEDATA, image);
>                res = curl_easy_perform(curl);
>
>                curl_easy_cleanup(curl);
>        }
>        fclose(image);
>        return (this -> thumbnailPath);
> }
>
> Everything goes fine until it calls curl_easy_perform and I get a
> segmentation fault error in some internal call to fwrite.
>
> I've do some modifications in the code above to pass
> CURLOPT_WRITEFUNCTION instead CURLOPT_WRITEDATA for the same purpose
> but when I checked the buffer value received by the function it was
> empty.
>
> This code works fine when I pass no options to curl object and prints
> the image data to stdio.
>
> I'm running a Kubuntu/Ubuntu environment with libcurl 7.18.0 and g++ 4.2.3.
>
> Thanks in advance.
>
> --
> Lucas Ces
> Laboratório de Tecnologia da Informação Aplicada - LTIA
> Universidade Estadual Paulista, Bauru - UNESP
> +55 14 3011-1596 / +55 11 8319-1327
> lucas.santos_at_ltia.fc.unesp.br
> www.ltia.fc.unesp.br
>
Received on 2008-10-30