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:
Benny Halevy
2024-03-27 14:36:57 +02:00
parent 882bb21903
commit 2c0e40a21f

View File

@@ -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) {