Skip to content

Reproducible crash in realloc with libcurl and libopenssl #1304

@HSNB

Description

@HSNB

The following code will always crash in realloc().

Specifically, in _mi_theap_realloc_zero() on this line:

Image
void curl_get_url()
{
	if (const auto curl = curl_easy_init()) {
		curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
		curl_easy_perform(curl);
		curl_easy_cleanup(curl);
	}
}

void main()
{
	curl_global_init(CURL_GLOBAL_ALL);

	std::list<std::future<void>> futures;

	for (int i = 0; i < 1024; ++i)
		futures.emplace_back(std::async(std::launch::async, curl_get_url));

	futures.clear();

	curl_global_cleanup();
}

The crash may occur inside OpenSSL, but sometimes also in libcurl. It's always crashing in this realloc function on this specific line in mimalloc though. Which makes me think it's mimallocs fault. The code does not crash without mimalloc.

Environment:

  • Visual Studio 2026
  • mimalloc version 3.3.2 static library (mimalloc-override-static-lib project in the given mimalloc.sln). linking to mimalloc-static.lib. Retargeted the project to v145 Platform Toolset on first open.
  • /MT build
  • mimalloc-static.lib is the first in the list of "Additional Dependencies"
  • mi_version is specified in "Force Symbol References"
  • mi_malloc is linked correctly, I've tested with mi_is_in_heap_region()
  • curl: static library (/MT)
  • openssl: static library (/MT)

From my observations while trying to understand why it's crashing, it seems mimalloc's realloc is not handling (expired?) threads well.

I checked some other issues and tried the dev3 branch. It also crashes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions