mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
utils: chunked_vector: push_back: call emplace_back
When pushing an element with a value referencing an exisiting element in the vector, we currently risking use-after-free when that element gets moved to a reallocated chunk, if capacity needs to be reserved, by that, invaliding the refernce to the existing element before it is used. This patch prepares for fixing that in the emplace path by converging to a single code path. Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
@@ -139,14 +139,10 @@ public:
|
||||
}
|
||||
|
||||
void push_back(const T& x) {
|
||||
reserve_for_push_back();
|
||||
new (addr(_size)) T(x);
|
||||
++_size;
|
||||
emplace_back(x);
|
||||
}
|
||||
void push_back(T&& x) {
|
||||
reserve_for_push_back();
|
||||
new (addr(_size)) T(std::move(x));
|
||||
++_size;
|
||||
emplace_back(std::move(x));
|
||||
}
|
||||
template <typename... Args>
|
||||
T& emplace_back(Args&&... args) {
|
||||
|
||||
Reference in New Issue
Block a user