-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Closed as not planned
Labels
kind: bugstate: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updatedthe issue has not been updated in a while and will be closed automatically soon unless it is updated
Description
Description
During ~basic_json, it is possible to get an exception from the allocation subsystem (quota/policy violation etc). This should be expected and accounted for.
Either:
- ~basic_json should not be using any allocation, OR
- upon exception a non allocating alternative to destroy should be used.
Reproduction steps
Throw any exception when allocation request is made during ~basic_json
Expected vs. actual results
Expected: ~basic_json
should not terminate a program.
Actual: it terminates the program
Minimal code example
#include <nlohmann/json.hpp>
using json = nlohmann::json;
thread_local bool should_throw = false;
struct QuotaReached : std::exception {};
void* operator new(std::size_t size) {
if (should_throw){
throw QuotaReached{};
}
void* ptr = std::malloc(size);
if (!ptr) {
throw std::bad_alloc();
}
return ptr;
}
int main()
{
{
auto j = json{1,2,3,4};
should_throw = true;
// `j` is destroyed, ~basic_json is noexcept
// allocation attempted, exception thrown
// terminate is called
}
}
https://godbolt.org/z/zh41cxW8j
Error messages
terminate called after throwing an instance of 'QuotaReached'
what(): std::exception
Program terminated with signal: SIGSEGV
Compiler and operating system
gcc 14.2 Linux
Library version
3.11.1
Validation
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.
Syed-Shahrukh-OSSRevival
Metadata
Metadata
Assignees
Labels
kind: bugstate: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updatedthe issue has not been updated in a while and will be closed automatically soon unless it is updated