Issue 83040
Summary Crash in install_bad_alloc_error_handler
Labels new issue
Assignees
Reporter fabianbs96
    The function `install_bad_alloc_error_handler` asserts that a bad_alloc error handler is not already installed. 
However, it actually checks for the fatal-error handler, not for the bad_alloc error handler, causing an assertion failure if a fatal-error handler is already installed.
Correct behavior would be to only crash if a bad_alloc handler is already installed, making it independent from fatal-error handlers.

Minimal working example: 

```C++
#include <llvm/Support/ErrorHandling.h>

int main() {
 llvm::install_fatal_error_handler([](void*,const char*,bool){});
 llvm::install_bad_alloc_error_handler([](void*,const char*,bool){}); // <-- Crash occurs here
}
```

Propsed Fix:

```Diff
diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp
index b8b3b7424ac6..c268543eb1fd 100644
--- a/llvm/lib/Support/ErrorHandling.cpp
+++ b/llvm/lib/Support/ErrorHandling.cpp
@@ -130,7 +130,7 @@ void llvm::install_bad_alloc_error_handler(fatal_error_handler_t handler,
 #if LLVM_ENABLE_THREADS == 1
   std::lock_guard<std::mutex> Lock(BadAllocErrorHandlerMutex);
 #endif
-  assert(!ErrorHandler && "Bad alloc error handler already registered!\n");
+ assert(!BadAllocErrorHandler && "Bad alloc error handler already registered!\n");
   BadAllocErrorHandler = handler;
 BadAllocErrorHandlerUserData = user_data;
 }
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to