curl-library
Memory Consumption
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;
xml->append(message->toString());
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
be.
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
{
private:
CURL *curl;
public:
HttpConnection(string * xml);
virtual ~HttpConnection();
};
And the class itself looks like this:
#include "HttpConnection.hpp"
using namespace std;
HttpConnection::HttpConnection(string * xml) {
curl_global_init(CURL_GLOBAL_NOTHING);
curl = curl_easy_init();
if(curl) {
string * message = new string;
message->append("xml=");
message->append(*xml);
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,
"http://localhost:8080/server/servlet/Insert");
curl_easy_perform(curl);
delete message;
}
}
HttpConnection::~HttpConnection()
{
curl_easy_cleanup(curl);
curl_global_cleanup();
}
Any help is appreciated!
Received on 2008-06-18