bitvect: do not leak on realloc failure, flagged by PVS-Studio

For #192.

* spot/misc/bitvect.hh: Here.
This commit is contained in:
Alexandre Duret-Lutz 2016-10-28 23:06:35 +02:00
parent 288f6ead9f
commit 24d19a6703

View file

@ -26,6 +26,7 @@
#include <iosfwd> #include <iosfwd>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <new>
namespace spot namespace spot
{ {
@ -112,8 +113,14 @@ namespace spot
} }
else else
{ {
auto old = storage_;
storage_ = static_cast<block_t*> storage_ = static_cast<block_t*>
(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; block_count_ = new_block_count;
} }