cURL / Mailing Lists / curl-library / Single Mail


Memory Consumption

From: Justin Thomas <>
Date: Tue, 17 Jun 2008 17:24:29 -0700

Hi there,

I'm new to libcurl and am having some problems with memory
consumption. I have a program that generates an XML message that is
fired off to a web server when it reaches a certain number of entries.
 The C++ code for the operation that invokes libcurl is wrapped in an
"HttpConnection" object. That object is called like ("message" is the
pre-configured XML message object):

string * xml = new string;
HttpConnection * connection = new HttpConnection(xml);
delete connection;
delete xml;

Without fail, my memory usage for this program increases by 12 - 16
bytes on each iteration. If I comment out the "HttpConnection" and
"delete connection" lines, things stabilize, so I'm confident the leak
is in that code. I'm guessing that I'm just missing a "cleanup" call
somewhere, but I've been searching and cannot figure out what it could

The HttpConnection class header looks this this:

#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <iostream>
#include <string>
#include <sstream>
#include <string.h>
#include <stdio.h>

using namespace std;

class HttpConnection
    CURL *curl;
    HttpConnection(string * xml);
    virtual ~HttpConnection();

And the class itself looks like this:

#include "HttpConnection.hpp"

using namespace std;

HttpConnection::HttpConnection(string * xml) {
    curl = curl_easy_init();

    if(curl) {
        string * message = new string;

        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, message->size());
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, message->c_str());
        FILE * nullFile = fopen("/dev/null", "w");
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullFile);
        curl_easy_setopt(curl, CURLOPT_URL,

        delete message;


Any help is appreciated!
Received on 2008-06-18