diff --git a/spot/misc/bitvect.hh b/spot/misc/bitvect.hh index 5ef490193..20bba37c7 100644 --- a/spot/misc/bitvect.hh +++ b/spot/misc/bitvect.hh @@ -26,6 +26,7 @@ #include #include #include +#include namespace spot { @@ -112,8 +113,14 @@ namespace spot } else { + auto old = storage_; storage_ = static_cast - (realloc(storage_, new_block_count * sizeof(block_t))); + (realloc(old, new_block_count * sizeof(block_t))); + if (!storage_) + { + free(old); + throw std::bad_alloc(); + } } block_count_ = new_block_count; }