cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: curl_slist_append segfault

From: Tim Johnson <tbj002_at_gmail.com>
Date: Wed, 31 Aug 2011 20:26:02 -0500

>
>
>
> >
> > I've got an application where I'm using cURL in a C program. The general
> > flow is going about like this:
> >
> > -----------------------------------------------------
> > struct curl_httppost *formpost=NULL;
> > struct curl_httppost *lastptr=NULL;
> > struct curl_slist *headerlist=NULL;
> > static const char buf[] = "Expect:";
> >
> > curl_global_init(CURL_GLOBAL_ALL);
> >
> > while (1)
> > {
> > ......
> > curl_formadd(.......);
> > ........
> > curl = curl_easy_init();
> > headerlist = curl_slist_append(headerlist, buf);
> > ........
> > curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
> > res = curl_easy_perform(curl);
> > curl_easy_cleanup(curl);
> > curl_formfree(formpost);
> > curl_slist_free_all (headerlist);
> > }
> > -----------------------------------------------------------
> >
> > I've explicitly listed all functions that should be using headerlist.
> >
> > On the second iteration through the loop, I get a segfault at the
> > curl_slist_append call. I'm hoping it's just something simple I'm doing.
> > I
> > searched around, the only thing I saw that looked like this was an issue
> > that appeared to be fixed by a patch back in 2003. I'm linking against
> > libcurl.so.4, which is a symlink to libcurl.so.4.2.0.
> >
> > Thanks for any help.
> >
> > -Tim
> > -------------- next part --------------
> >
> > On Mon, Aug 29, 2011 at 10:48 PM, Tim Johnson <tbj002_at_gmail.com> wrote:
> > [snip]
> > > ? ? curl_slist_free_all (headerlist);
> > [snip]
> > > I've?explicitly?listed all functions that should be using headerlist.
> > > On the second iteration through the loop, I get a segfault ?at the
> > > curl_slist_append call. ?I'm hoping it's just something simple I'm
> doing.
> > ?I
> > > searched around, the only thing I saw that looked like this was an
> issue
> > > that appeared to be fixed by a patch back in 2003. ? I'm linking
> against
> > > libcurl.so.4, which is a symlink to libcurl.so.4.2.0.
> > > Thanks for any help.
> > > -Tim
> >
> > Maybe add
> >
> > headerlist = NULL;
> >
> > after the above line to make curl_slist_append() start fresh in the
> > loop on each iteration?
> >
> > Lars Nilsson
> >
> >
> >
> > ------------------------------
> >
> >
>
> Thanks Lars, I just gave that a try. Still no luck.
>
> Any other ideas out there? Maybe try another version of libcurl? Or is
> there a way to extract out some information about the curl_slist to try and
> detect what is going wrong?
>
> Thanks
>
> -Tim
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://cool.haxx.se/pipermail/curl-users/attachments/20110830/54665f48/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 2
> Date: Tue, 30 Aug 2011 13:36:39 +0200 (CEST)
> From: Daniel Stenberg <daniel_at_haxx.se>
> To: the curl tool <curl-users_at_cool.haxx.se>
> Subject: Re: curl_slist_append segfault
> Message-ID: <alpine.DEB.2.00.1108301333160.11462_at_tvnag.unkk.fr>
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
>
> On Tue, 30 Aug 2011, Tim Johnson wrote:
>
> Please be aware that you would reach the bunch of libcurl hackers properly
> on
> the curl-library list. This list is for users of the curl command line
> tool.
>
> I strongly suggest that you take follow-ups on this issue to that list
> instead.
>
> >> Maybe add
> >>
> >> headerlist = NULL;
> >>
> >> after the above line to make curl_slist_append() start fresh in the
> >> loop on each iteration?
> >
> > Thanks Lars, I just gave that a try. Still no luck.
> >
> > Any other ideas out there?
>
> You need to show us more exact details for us to tell. Like a complete
> program
> that repeats the problem
>
> > Maybe try another version of libcurl?
>
> I don't think so. I'm convinced the problem you're having is due to a
> mistake
> in your code and not in libcurl...
>
> > Or is there a way to extract out some information about the curl_slist to
> > try and detect what is going wrong?
>
> The curl_slist is just a linked list. You can easily browser and traverse
> that
> yourself using your code or a debugger etc.
>
>

Fair enough. Thanks for the help, and I'll strip this program down to more
general version that can show the issue, and I'll repost in curl-library.

Thanks again,

-Tim

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-09-01