cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Correct use of curl_easy_getinfo

From: Till Elsner <till_at_0xaa55.org>
Date: Mon, 5 Dec 2011 16:08:33 +0100

Daniel Stenberg (Mon, 05. 12. 2011, 15:35):
> On Mon, 5 Dec 2011, Till Elsner wrote:
>
> > But when I call curl_easy_getinfo on the handle after having fetched the
> > site to get the effective URL, I still works for the FIRST connection.
> > However, on the next connection using the same handle, the program receives
> > segmentation fault while performing curl_easy_perform.
>
> Are you using a recent libcurl version?

I'm using 7.21.4.

>
> Any chance you can provide source code to a little example we can use to
> repeat this problem?

Basically, the function I use to retrieve a URL is the
following:

01 struct doc_info_st *open_url(const char *url, CURL *curl)
02 {
03 struct doc_info_st *doc_info=doc_info_init();
04 curl_easy_reset(curl);
05 /* prepare error buffer */
06 doc_info->error=(char *)malloc(CURL_ERROR_SIZE);
07 memset(doc_info->error, 0, CURL_ERROR_SIZE);
08 /* fetch content: prepare cURL handler */
09 curl_easy_setopt(curl, CURLOPT_URL, url);
10 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
11 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &curl_write);
12 curl_easy_setopt(curl, CURLOPT_WRITEDATA, doc_info);
13 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, doc_info->error);
14 /* ...fire */
15 doc_info->loaded=1;
16 if (curl_easy_perform(curl)!=0)
17 {
18 doc_info->loaded=0;
19 }
20 else {
21 /* set url */
22 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &doc_info->url);
23 /* parse source */
24 if (parse_html(doc_info)==-1)
25 {
26 doc_info->loaded=0;
27 memcpy(doc_info->error, "Invalid HTML!", 14);
28 }
29 }
30 return doc_info;
31 }

Although segfault happens in line 16 on the second use, the problem *seems* to
be line 22, as the problem disappears if this line is removed.

>
> --
>
> / daniel.haxx.se
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html

-- 
Till Elsner                                                   []
till_at_0xAA55.org (Email & XMPP)                                  []
irc.0xaa55.org #praty                                       [][][]
############################## GPG ###############################
#                      KeyID=0xFCFF4656                          #
# fingerprint: 1A1E 3B61 6956 07E3 2CB8 D0F8 791F 52F8 FCFF 4656 #
##################################################################
 ()  ascii ribbon campaign  - against html e-mail
 /\   www.asciiribbon.org   - against proprietary attachments

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html

  • application/pgp-signature attachment: stored
Received on 2011-12-05