cURL / Mailing Lists / curl-library / Single Mail

curl-library

SSL Cert information filling up memory

From: Jacques Verryn <jacques_at_digidruid.com>
Date: Mon, 12 Jan 2009 14:10:22 +0200

OS/Dist: Linux - Fedora 10
libCurl Version: libcurl-7.18.2-7.fc10.i386

I'm running into a memory issue when doing https calls using the
curl_easy interface.
I've got the following stripped down code that causes the error.
====================================================
#include <curl/curl.h>
#include <string>
#include <stdlib.h>

int main (int argc, char ** argv)
{
   curl_global_init(CURL_GLOBAL_ALL);
   CURL * pcurl;
   CURLcode res = CURLE_OK;
   std::string url=argv[1];
   std::string certfile=argv[2];
   int iattempts=atoi(argv[3]);

   printf("Create curl connection\n");
   pcurl = curl_easy_init();

   if ((res = curl_easy_setopt(pcurl,CURLOPT_CAINFO,certfile.c_str()))
!= CURLE_OK)
   {
      printf("CURL ERROR: Line %i Error: %i\n",__LINE__,res);
      curl_easy_cleanup(pcurl);
      curl_global_cleanup();
      return res;
   }
   if ((res = curl_easy_setopt(pcurl,CURLOPT_SSL_VERIFYPEER,1)) != CURLE_OK)
   {
      printf("CURL ERROR: Line %i Error: %i\n",__LINE__,res);
      curl_easy_cleanup(pcurl);
      curl_global_cleanup();
      return res;

   }

   if ((res = curl_easy_setopt(pcurl, CURLOPT_URL, url.c_str())) !=
CURLE_OK)
   {
      printf("CURL ERROR: Line %i Error: %i\n",__LINE__,res);
      curl_easy_cleanup(pcurl);
      curl_global_cleanup();
      return res;
   }

   for (int i=0;i<iattempts;i++)
   {
      printf("Doing call number: %i\n",i);
      // Perform the SSL call
      if ((res = curl_easy_perform(pcurl)) != CURLE_OK)
      {
         printf("CURL ERROR: Line %i Error: %i\n",__LINE__,res);
         curl_easy_cleanup(pcurl);
         curl_global_cleanup();
         return res;
      }
     
      usleep(250000);
   }

   curl_easy_cleanup(pcurl);
   pcurl=NULL;

   curl_global_cleanup();
   printf("PID:%d\n",getpid());
   abort();
   return 0;
}
====================================================
compile: g++ -o curlleak -lcurl curlleak.cpp
Usage: ./curlleak <https_url> <cacertfile> <iterations>

If I open the core file generated as a result of the abort() on the
second last line,
I can see the CA information repeat many times over. The more
iterations, the more the
cacert info repeats.

The above code is the preferred way, for me, to implement my solution,
but I also tried putting a curl_easy_reset
at the top of the for-loop and resetting all the options on each iteration.
I also tried creating a new curl_easy_init connection for each
iteration, but the results remained the same.

Regards
Jacques
Received on 2009-01-12