Haxx ad

curl's project page on


cURL > Mailing List > Monthly Index > Single Mail

curl-library Mailing List Archives

Re: linux curl_easy_perform error

From: Cornu Nicolas <>
Date: Sat, 30 Apr 2005 21:51:20 +0200

full source:

#include <stdio.h>
#include <iostream>
#include <curl/curl.h>
#include <string>
#include <exception>
#include "CommSPG.h"
#include "Globals.h"
using namespace std;
namespace SMSD
namespace COMM
unsigned int CommSPG::timeOut;
std::string CommSPG::proxy = "";
std::string CommSPG::proxyUserPwd = "";
std::string CommSPG::certType;
std::string CommSPG::certFileName;
std::string CommSPG::keyPass;
std::string CommSPG::keyType;
std::string CommSPG::key;
CommSPG::MemoryStruct * CommSPG::mem;

void CommSPG::init(const std::string& leProxy, const std::string&
leProxyUserPwd,int leTimeOut)
void CommSPG::initSSL(char *leCertType, char *leCertFileName, char
*leKeyPass, char *leKeyType, char *laKey)
void * CommSPG::myrealloc(void *ptr, size_t size)
    /* There might be a realloc() out there that doesn't like reallocing
    NULL pointers, so we take care of it here */
    return realloc(ptr, size);
    return malloc(size);

size_t CommSPG::WriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
void *data)
    register int realsize = size * nmemb;
    mem = (struct MemoryStruct *)data;
    mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1);
    if (mem->memory)
        memcpy(&(mem->memory[mem->size]), ptr, realsize);
        mem->size += realsize;
        mem->memory[mem->size] = 0;
    return realsize;

std::string CommSPG::InterrogerSPG(const std::string& url, const
std::string& data)
    CURL *curl;
    CURLcode res;
    std::string reponse;
    struct MemoryStruct chunk;
    chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
    chunk.size = 0; /* no data at this point */
    struct curl_slist *headerlist=NULL;
    curl = curl_easy_init();
    GLOBALS::logger->debug() << "CommSPG:InterrogerSPG: " << url << " ,data:
" << data; GLOBALS::logger->write();

            GLOBALS::logger->debug() << "CommSPG:InterrogerSPG: defining
curl proxy."; GLOBALS::logger->write();
            curl_easy_setopt(curl, CURLOPT_PROXY, proxy.c_str());
            GLOBALS::logger->debug() << "CommSPG:InterrogerSPG: defining
proxy password"; GLOBALS::logger->write();
        curl_easy_setopt(curl, CURLOPT_URL,;
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS,;
        GLOBALS::logger->debug() << "CommSPG:InterrogerSPG: performing curl
request (curl_easy_perform)"; GLOBALS::logger->write();
        res = curl_easy_perform(curl);
        GLOBALS::logger->debug() << "CommSPG:InterrogerSPG: performing curl
cleanup (curl_easy_cleanup)"; GLOBALS::logger->write();

    if(chunk.size==0) {
    GLOBALS::logger->debug() << "CommSPG:InterrogerSPG: exception thrown";
      throw "Erreur de communication\n";
    reponse = (string)chunk.memory;
    GLOBALS::logger->debug() << "CommSPG:InterrogerSPG: return next
operation"; GLOBALS::logger->write();
    return reponse;

In fact no error when the url is correct else this crash.


----- Original Message -----
From: "Daniel Stenberg" <>
To: "libcurl development" <>
Sent: Saturday, April 30, 2005 8:32 PM
Subject: Re: linux curl_easy_perform error

> On Sat, 30 Apr 2005, Cornu Nicolas wrote:
>> I am developping a linux windows portable server. I use libcurl and my
>> app crash on linux on curl_easy_perfrom
> If you are using a very recent libcurl the most likely causes for your
> problem, are 1) a problem in your write callback, or 2) you messed up the
> memory somehow before you called libcurl so that a malloc/free function
> within libcurl goes bananas.
> If you provide a full example source code (that compiles as-is) and that
> crashes when used with a given public URL, I'll be happy to verify my
> claim.
> --
> Commercial curl and libcurl Technical Support:
Received on 2005-04-30

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET