bitvect: do not leak on realloc failure, flagged by PVS-Studio
For #192. * spot/misc/bitvect.hh: Here.
This commit is contained in:
parent
288f6ead9f
commit
24d19a6703
1 changed files with 8 additions and 1 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue