Commit 03e99d2e authored by Soren Lassen's avatar Soren Lassen Committed by Anton Likhtarov

Fix some folly memory leaks found with clang:dev + asan

Summary:
Reverts the revert of the small_vector and test parts of D1569246.
I'm saving the SocketAddress fix for later, because it caused problems
and needs more research.

Test Plan:
unit tests with clang:dev/asan

Reviewed By: njormrod@fb.com

Subscribers: mathieubaudet, philipp, meyering, njormrod

FB internal diff: D1575574

Blame Revision: D1575190
parent d8e71911
main 2016.07.26 v2022.02.14.00 v2022.02.07.00 v2022.01.31.00 v2022.01.24.00 v2022.01.17.00 v2022.01.10.00 v2022.01.03.00 v2021.12.27.00 v2021.12.20.00 v2021.12.13.00 v2021.12.06.00 v2021.11.29.00 v2021.11.15.00 v2021.11.08.00 v2021.11.01.00 v2021.10.25.00 v2021.10.18.00 v2021.10.11.00 v2021.10.04.00 v2021.09.27.00 v2021.09.20.00 v2021.09.13.00 v2021.09.06.00 v2021.08.30.00 v2021.08.23.00 v2021.08.02.00 v2021.07.22.00 v2021.07.20.01 v2021.07.20.00 v2021.06.28.00 v2021.06.14.00 v2021.06.07.00 v2021.05.31.00 v2021.05.24.00 v2021.05.17.00 v2021.05.10.00 v2021.05.03.00 v2021.04.26.00 v2021.04.19.00 v2021.04.12.00 v2021.04.05.00 v2021.03.29.00 v2021.03.22.00 v2021.03.15.00 v2021.03.08.00 v2021.03.01.00 v2021.02.22.00 v2021.02.15.00 v2021.02.08.00 v2021.02.01.00 v2021.01.25.00 v2021.01.18.01 v2021.01.18.00 v2021.01.11.00 v2021.01.04.00 v2020.12.28.00 v2020.12.21.00 v2020.12.14.00 v2020.12.07.00 v2020.11.30.00 v2020.11.23.00 v2020.11.16.00 v2020.11.09.00 v2020.11.02.00 v2020.10.26.00 v2020.10.19.00 v2020.10.12.00 v2020.10.05.00 v2020.09.28.00 v2020.09.21.00 v2020.09.14.00 v2020.09.07.00 v2020.08.31.00 v2020.08.24.00 v2020.08.17.00 v2020.08.10.00 v2020.08.03.00 v2020.07.27.00 v2020.07.20.00 v2020.07.13.00 v2020.07.06.00 v2020.06.29.00 v2020.06.15.00 v2020.06.08.00 v2020.06.01.00 v2020.05.25.00 v2020.05.18.00 v2020.05.11.00 v2020.05.04.00 v2020.04.27.00 v2020.04.20.00 v2020.04.13.00 v2020.04.06.00 v2020.03.30.00 v2020.03.23.00 v2020.03.16.00 v2020.03.09.00 v2020.03.02.00 v2020.02.24.00 v2020.02.17.00 v2020.02.10.00 v2020.02.03.00 v2020.01.27.00 v2020.01.20.00 v2020.01.13.00 v2020.01.06.00 v2019.12.30.00 v2019.12.23.00 v2019.12.16.00 v2019.12.09.00 v2019.12.06.00 v2019.12.02.00 v2019.11.11.00 v2019.11.04.00 v2019.10.28.00 v2019.10.21.00 v2019.10.14.00 v2019.10.07.00 v2019.09.30.00 v2019.09.23.00 v2019.09.16.00 v2019.09.09.00 v2019.09.02.00 v2019.08.26.00 v2019.08.19.00 v2019.08.12.00 v2019.08.05.00 v2019.07.29.00 v2019.07.22.00 v2019.06.17.00 v2019.06.10.00 v2019.06.03.00 v2019.05.27.00 v2019.05.20.00 v2019.05.13.00 v2019.05.06.00 v2019.04.29.00 v2019.04.22.00 v2019.04.15.00 v2019.04.08.00 v2019.04.01.00 v2019.03.25.00 v2019.03.18.00 v2019.03.04.00 v2019.02.25.00 v2019.02.18.00 v2019.02.11.00 v2019.02.04.00 v2019.01.28.00 v2019.01.21.00 v2019.01.14.00 v2019.01.07.00 v2018.12.31.00 v2018.12.24.00 v2018.12.17.00 v2018.12.10.00 v2018.12.03.00 v2018.11.26.00 v2018.11.19.00 v2018.11.12.00 v2018.11.05.00 v2018.10.29.00 v2018.10.22.00 v2018.10.15.00 v2018.10.08.00 v2018.10.01.00 v2018.09.24.00 v2018.09.17.00 v2018.09.10.01 v2018.09.10.00 v2018.09.03.01 v2018.09.03.00 v2018.08.27.00 v2018.08.20.00 v2018.08.13.00 v2018.08.09.00 v2018.08.06.00 v2018.07.30.00 v2018.07.23.00 v2018.07.16.00 v2018.07.09.00 v2018.07.02.00 v2018.06.25.00 v2018.06.18.00 v2018.06.11.00 v2018.06.04.00 v2018.05.28.00 v2018.05.21.00 v2018.05.14.00 v2018.05.07.00 v2018.04.30.00 v2018.04.23.00 v2018.04.16.00 v2018.04.09.00 v2018.04.02.00 v2018.03.26.00 v2018.03.19.00 v2018.03.12.00 v2018.03.05.00 v2018.02.26.00 v2018.02.19.00 v2018.02.12.00 v2018.02.05.00 v2018.01.29.00 v2018.01.22.00 v2018.01.15.00 v2018.01.08.00 v2018.01.01.00 v2017.12.25.00 v2017.12.18.00 v2017.12.11.00 v2017.12.04.00 v2017.11.27.00 v2017.11.20.00 v2017.11.13.00 v2017.11.06.00 v2017.10.30.00 v2017.10.23.00 v2017.10.16.00 v2017.10.09.00 v2017.10.02.00 v2017.09.25.00 v2017.09.18.00 v2017.09.11.00 v2017.09.04.00 v2017.08.28.00 v2017.08.21.00 v2017.08.14.00 v2017.08.07.00 v2017.07.31.00 v2017.07.24.00 v2017.07.17.01 v2017.07.17.00 v2017.07.10.00 v2017.07.03.00 v2017.06.26.01 v2017.06.26.00 v2017.06.19.00 v2017.06.12.00 v2017.06.05.00 v2017.05.29.00 v2017.05.22.00 v2017.05.15.00 v2017.05.08.00 v2017.05.01.00 v2017.04.24.00 v2017.04.17.00 v2017.04.10.00 v2017.04.03.00 v2017.03.27.00 v2017.03.20.00 v2017.03.13.00 v2017.03.06.00 v2016.12.19.00 v2016.12.12.00 v2016.12.05.00 v2016.11.28.00 v2016.11.21.00 v2016.11.14.00 v2016.11.07.00 v2016.10.31.00 v2016.10.24.00 v2016.10.17.00 v2016.10.10.00 v2016.10.03.00 v2016.09.26.00 v2016.09.19.00 v2016.09.12.01 v2016.09.12.00 v2016.09.05.00 v2016.08.29.00 v2016.08.22.00 v2016.08.15.00 v2016.08.08.00 v2016.08.01.00 v2016.07.29.00 v0.57.0 v0.56.0 v0.55.0 v0.54.0 v0.53.0 v0.52.0 v0.51.0 v0.50.0 v0.49.1 v0.49.0 v0.48.0 v0.47.0 v0.45.0 v0.43.0 v0.42.0 v0.41.0 v0.40.0 v0.39.0 v0.38.0 v0.37.0 v0.36.0 v0.35.0 v0.34.0 v0.33.0 v0.32.0 v0.31.0 v0.30.0 v0.29.0 v0.28.0 v0.27.0 v0.26.0 v0.25.0 v0.24.0 v0.23.0 v0.22.0 deprecate-dynamic-initializer
No related merge requests found
...@@ -391,13 +391,16 @@ public: ...@@ -391,13 +391,16 @@ public:
try { try {
std::uninitialized_copy(o.begin(), o.end(), begin()); std::uninitialized_copy(o.begin(), o.end(), begin());
} catch (...) { } catch (...) {
if (this->isExtern()) u.freeHeap(); if (this->isExtern()) {
u.freeHeap();
}
throw; throw;
} }
this->setSize(n); this->setSize(n);
} }
small_vector(small_vector&& o) { small_vector(small_vector&& o)
noexcept(std::is_nothrow_move_constructible<Value>::value) {
if (o.isExtern()) { if (o.isExtern()) {
swap(o); swap(o);
} else { } else {
...@@ -877,18 +880,31 @@ private: ...@@ -877,18 +880,31 @@ private:
auto distance = std::distance(first, last); auto distance = std::distance(first, last);
makeSize(distance); makeSize(distance);
this->setSize(distance); this->setSize(distance);
try {
detail::populateMemForward(data(), distance, detail::populateMemForward(data(), distance,
[&] (void* p) { new (p) value_type(*first++); } [&] (void* p) { new (p) value_type(*first++); }
); );
} catch (...) {
if (this->isExtern()) {
u.freeHeap();
}
throw;
}
} }
void doConstruct(size_type n, value_type const& val) { void doConstruct(size_type n, value_type const& val) {
makeSize(n); makeSize(n);
this->setSize(n); this->setSize(n);
detail::populateMemForward(data(), n, try {
[&] (void* p) { new (p) value_type(val); } detail::populateMemForward(data(), n,
); [&] (void* p) { new (p) value_type(val); }
);
} catch (...) {
if (this->isExtern()) {
u.freeHeap();
}
throw;
}
} }
// The true_type means we should forward to the size_t,value_type // The true_type means we should forward to the size_t,value_type
......
...@@ -61,6 +61,7 @@ TEST(PackedSyncPtr, Basic) { ...@@ -61,6 +61,7 @@ TEST(PackedSyncPtr, Basic) {
EXPECT_EQ(sp.extra(), 0x13); EXPECT_EQ(sp.extra(), 0x13);
EXPECT_EQ(sp.get(), newP); EXPECT_EQ(sp.get(), newP);
sp.unlock(); sp.unlock();
delete sp.get();
} }
// Here we use the PackedSyncPtr to lock the whole SyncVec (base, *base, and sz) // Here we use the PackedSyncPtr to lock the whole SyncVec (base, *base, and sz)
...@@ -68,6 +69,7 @@ template<typename T> ...@@ -68,6 +69,7 @@ template<typename T>
struct SyncVec { struct SyncVec {
PackedSyncPtr<T> base; PackedSyncPtr<T> base;
SyncVec() { base.init(); } SyncVec() { base.init(); }
~SyncVec() { free(base.get()); }
void push_back(const T& t) { void push_back(const T& t) {
base.set((T*) realloc(base.get(), base.set((T*) realloc(base.get(),
(base.extra() + 1) * sizeof(T))); (base.extra() + 1) * sizeof(T)));
......
...@@ -184,7 +184,7 @@ TEST(ThreadLocal, SimpleRepeatDestructor) { ...@@ -184,7 +184,7 @@ TEST(ThreadLocal, SimpleRepeatDestructor) {
TEST(ThreadLocal, InterleavedDestructors) { TEST(ThreadLocal, InterleavedDestructors) {
Widget::totalVal_ = 0; Widget::totalVal_ = 0;
ThreadLocal<Widget>* w = nullptr; std::unique_ptr<ThreadLocal<Widget>> w;
int wVersion = 0; int wVersion = 0;
const int wVersionMax = 2; const int wVersionMax = 2;
int thIter = 0; int thIter = 0;
...@@ -214,8 +214,7 @@ TEST(ThreadLocal, InterleavedDestructors) { ...@@ -214,8 +214,7 @@ TEST(ThreadLocal, InterleavedDestructors) {
{ {
std::lock_guard<std::mutex> g(lock); std::lock_guard<std::mutex> g(lock);
thIterPrev = thIter; thIterPrev = thIter;
delete w; w.reset(new ThreadLocal<Widget>());
w = new ThreadLocal<Widget>();
++wVersion; ++wVersion;
} }
while (true) { while (true) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment