From 24d19a6703af8b354f714d28f9e6da9ff6efc785 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Fri, 28 Oct 2016 23:06:35 +0200 Subject: [PATCH] bitvect: do not leak on realloc failure, flagged by PVS-Studio For #192. * spot/misc/bitvect.hh: Here. --- spot/misc/bitvect.hh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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; }