From 207cb35c55420364ec82e7532485ce0d5c3a09f1 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 22 Mar 2022 16:26:18 +0400 Subject: [PATCH] Report how much memory was requested on OOM. --- Telegram/SourceFiles/core/crash_reports.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Telegram/SourceFiles/core/crash_reports.cpp b/Telegram/SourceFiles/core/crash_reports.cpp index cbea96be25..0c5d401316 100644 --- a/Telegram/SourceFiles/core/crash_reports.cpp +++ b/Telegram/SourceFiles/core/crash_reports.cpp @@ -18,6 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS #ifdef Q_OS_WIN +#include + #pragma warning(push) #pragma warning(disable:4091) #include "client/windows/handler/exception_handler.h" @@ -105,11 +107,20 @@ std::unique_ptr ReservedMemory; void InstallOperatorNewHandler() { ReservedMemory = std::make_unique(); +#ifdef Q_OS_WIN + _set_new_handler([](size_t requested) -> int { + _set_new_handler(nullptr); + ReservedMemory.reset(); + CrashReports::SetAnnotation("Requested", QString::number(requested)); + Unexpected("Could not allocate!"); + }); +#else // Q_OS_WIN std::set_new_handler([] { std::set_new_handler(nullptr); ReservedMemory.reset(); Unexpected("Could not allocate!"); }); +#endif // Q_OS_WIN } void InstallQtMessageHandler() {