I'm using a function I found here to save a webpage to memory with cURL:
struct WebpageData {
char *pageData;
size_t size;
};
size_t storePage(void *input, size_t size, size_t nmemb, void *output) {
size_t realsize = size * nmemb;
struct WebpageData *page = (struct WebpageData *)output;
page->pageData = (char *)realloc(page->pageData, page->size + realsize + 1);
if(page->pageData) {
memcpy(&(page->pageData[page->size]), input, realsize);
page->size += realsize;
page->pageData[page->size] = 0;
}
return realsize;
}
and find the line:
page->pageData = (char *)realloc(page->pageData, page->size + realsize + 1);
is causing a memory leak of a few hundred bytes per call. The only real change I've made from the original source is casting the line in question to a (char *), which my compiler (gcc, g++ specifically if it's a c/c++ issue, but gcc also wouldn't compile with the uncast statement) insisted upon, but I assume this is the source of the leak. Can anyone elucidate?
Thanks