Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Memory free event without a matching allocation" when using std::format with {:L} #1019

Open
adriengivry opened this issue Apr 4, 2025 · 2 comments

Comments

@adriengivry
Copy link

adriengivry commented Apr 4, 2025

Description

On the game engine I'm working on, using C++20 and std::format, it seems like the Tracy profiler encounters a "Memory free event without a matching allocation" when using std::format(std::locale(""), "{:L}", 10).

For reference, here are the operators we overloaded:

void* operator new(std::size_t size);
void operator delete(void* ptr) noexcept;
void operator delete(void* ptr, std::size_t size) noexcept;
void* operator new[](std::size_t size);
void operator delete[](void* ptr) noexcept;
void operator delete[](void* ptr, std::size_t size) noexcept;
void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
void operator delete(void* ptr, const std::nothrow_t&) noexcept;
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept;
void operator delete[](void* ptr, const std::nothrow_t&) noexcept;
void* operator new(std::size_t size, std::align_val_t alignment);
void operator delete(void* ptr, std::align_val_t alignment) noexcept;
void* operator new[](std::size_t size, std::align_val_t alignment);
void operator delete[](void* ptr, std::align_val_t alignment) noexcept;
void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
void* operator new(std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept;
void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;

It works fine when using std::locale(), which defaults to the C locale.

Note: std::locale("") being the user's locale (from its regional settings). In my case, it's en_US

Expected Behaviour

Not sure, is it a false positive, or is there something wrong with std::format?

Environment

MSVC: Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34438 for x86

@mcourteaux
Copy link
Contributor

I'm assuming you did a global new and delete override, or even more tricky a global malloc() and free() override. Might be an internal allocation happening in the standard C++ library, which gets executed before Tracy's static initializers ran. These are super hard to fix. Tracy has an option to ignore those errors, however this option is not yet user controllable. You can modify Tracy source code here:

m_ignoreMemFreeFaults = ( welcome.flags & WelcomeFlag::OnDemand ) || ( welcome.flags & WelcomeFlag::IsApple );

to check for an environment variable, for example: || getenv("TRACY_IGNORE_MEM_FREE_FAULT").

@adriengivry
Copy link
Author

adriengivry commented Apr 8, 2025

So far our workaround has been to avoid using std::locale("") when tracy memory profiling is enabled. We're definitely looking for a more future-proof solution, so we'll look into that recommendation.

I've update the issue description to include the operators we tried to overload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants