cURL / Mailing Lists / curl-users / Single Mail

curl-users

memeory leak, was: --interface dumps core

From: Georg Horn <horn_at_koblenz-net.de>
Date: Mon, 9 Oct 2000 09:06:03 +0200

Hi,

On Sun, Oct 08, 2000 at 02:54:38PM +0200, Daniel Stenberg wrote:

> If the data happened to become NULL, the free() will survive but you'll
> instead experience a memory leak. It might be the one you report in your
> other mail!
>
> Try this patch instead of removing the free(). It should be a better fix:
>
> diff -u -r1.14 hostip.c
> [...]

Thanks, that works and the memory consumption has decreased too...
I just needed the --interface on friday afternoon and it crashed. So i was
happy to get it working by removing the free()...

The memory usage of the following C program still grows slowly. If i put the
loop just around the curl_easy_perform() call, it even grows quicker.

Bye,
Georg

--- cut ---

#include <stdio.h>

#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

int main(int argc, char *argv[])
{
    int i;
    CURL *curl_handle;
    char errbuf[CURL_ERROR_SIZE];
    
    if (argc < 2) {
        fprintf(stderr, "usage: %s url\n", argv[0]);
        exit(1);
    }

for (i=0; i<10000; i++) {
    /* Init the curl session */
    curl_handle = curl_easy_init();

    /* Set URL to get */
    curl_easy_setopt(curl_handle, CURLOPT_URL, argv[1]);

    /* No progress meter please */
    curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);

    /* Shut up completely */
    curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1);

    /* Follow location headers */
    curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);

    /* Save cookies */
    curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "cookies");

    /* Set timeout */
    curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30);

    /* Store error messages here */
    curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, errbuf);

    /* get it! */
    if (curl_easy_perform(curl_handle) != 0) {
        printf("Error: %s\n", errbuf);
    } else {
        printf("Ok: %d bytes received\n", bytes_written);
    }

    /* cleanup curl stuff */
    curl_easy_cleanup(curl_handle);
}

    return 0;
}
Received on 2000-10-09