cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Crash in curl

From: Andreas Volz <lists_at_brachttal.net>
Date: Mon, 18 Feb 2008 00:43:20 +0100

Am Sun, 17 Feb 2008 20:29:24 +0100 (CET) schrieb Daniel Stenberg:

> > It's not so easy to replace a system component like curl on Ubuntu
> > if not included in the distribution.
>
> Oh it certainly is very easy.
>
> Build libcurl and install it somewhere brand new:
>
> ./configure --prefix=/home/me/test-curl-install
> make
> make install
>
> Then you rebuild your application to use the temporary install path
> and you test your application to see if the problem persists.
>
> (and when you're done testing, you can just whipe the entire test
> install dir)

Ok, I'll do try that.

> >> Seeing you run on Linux, have you tried running your app with
> >> valgrind?
> >
> > Yes, but no error is reported while using valgrind. I simply see a
> > segfault and nothing else. No error summary from valgrind. It looks
> > as if valgrind dies too. I tested my valgrind installation with
> > various other tools and it works. I don't understand it.
>
> Well, that would rather indicate that there's no memory problem crazy
> enough for valgrind to trap, but possibly a memory error crazy enough
> to crash libcurl.
>
> Anyway, if you can repeat this with 7.18.0 I think your next step
> would be to try to make a stand-alone application that can repeat
> this problem, or if that's not possible try to narrow down what usage
> patterns that cause the problem.

I decided to rewrite the places where I handle my downloaded files in
memory complete. But now I get the same problem again. I don't find the
error. I'll show you my code below. Maybe you're able to see a problem.

class Download : public sigc::trackable
{
...
  FILE *m_file;
  CURL *m_curlHandle;
  string m_filename;
  string m_url;
  Memory m_memory;
  ThreadState threadState;
  bool m_fetch;
  bool m_threading;
};

void Download::initCurl ()
{
  m_curlHandle = curl_easy_init();
  
  // send all data to this function
  curl_easy_setopt(m_curlHandle, CURLOPT_WRITEFUNCTION, writeCallback);
  
  curl_easy_setopt(m_curlHandle, CURLOPT_WRITEDATA, this);

  /* some servers don't like requests that are made without a user-agent
     field, so we provide one */
  curl_easy_setopt(m_curlHandle, CURLOPT_USERAGENT,
  "libcurl-agent/1.0");

  curl_easy_setopt(m_curlHandle, CURLOPT_NOPROGRESS, FALSE);
  curl_easy_setopt(m_curlHandle, CURLOPT_PROGRESSFUNCTION,
   progressCallback);

  curl_easy_setopt(m_curlHandle, CURLOPT_PROGRESSDATA, this);
  // enable redirect
  curl_easy_setopt(m_curlHandle, CURLOPT_FOLLOWLOCATION, 1);
}

int Download::webget (const string &url, const string &filename)
{
  long httpResponse;
  
  // specify URL to get
  curl_easy_setopt(m_curlHandle, CURLOPT_URL, url.c_str ());

  // open the file
  m_file = fopen (filename.c_str (), "w");
  if (!m_file)
  {
    // ignore, simply don't open a file
    // TODO: report error
  }
  //cout << "+curl_easy_perform" << endl;
  // download the file from network with curl and block here until
  // finished

  CURLcode cc = curl_easy_perform (m_curlHandle);
  cout << "Curl return (do something usefull with it): " << cc << endl;
  //cout << "-curl_easy_perform" << endl;
  
  // file could be closed after curl finished downloading
  if (m_file)
  {
    fclose (m_file);
  }
  
  curl_easy_getinfo (m_curlHandle , CURLINFO_HTTP_CODE , &httpResponse);
  
  return httpResponse;
}

The code above should work. In most cases it works without problems.
But sometimes I get that crash.

regards
Andreas
Received on 2008-02-18