Skip to content

Memory leak in async_thrdd_init when a request fails #17602

@hiimmat

Description

@hiimmat

I did this

When a request is made to a non-existent URL, the hostname in async_thrdd_init is not properly cleaned up:
https://github.com/curl/curl/blame/master/lib/asyn-thrdd.c#L426

As a result, on subsequent requests, the old hostname value remains and is simply overwritten with the new one, without ever being freed. This leads to the previous hostname lingering in memory.

Sample for reproduction:

#include <stdio.h>
#include <curl/curl.h>


size_t ignore_output( void *ptr, size_t size, size_t nmemb, void *stream)
{
    (void) ptr;
    (void) stream;
    return size * nmemb;
}

int main()
{
    CURL *curl;
    curl = curl_easy_init();

    if(!curl) {
        printf("curl initialization failed\n");
        return -1;
    }

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &ignore_output);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);

    curl_easy_setopt(curl, CURLOPT_URL, "invalid_url_one");
    curl_easy_perform(curl);

    curl_easy_setopt(curl, CURLOPT_URL, "invalid_url_two");
    curl_easy_perform(curl);

    curl_easy_cleanup(curl);

    return 0;
}

I expected the following

No response

curl/libcurl version

curl 8.14.0

operating system

Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions