From: Danny Guo Date: Wed, 24 Sep 2014 18:48:36 +0000 (-0700) Subject: Revert "Fix folly memory leaks found with clang:dev + asan." X-Git-Tag: v0.22.0~329 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f760023d339249ca3f6e40ebee69128d9850f925;p=folly.git Revert "Fix folly memory leaks found with clang:dev + asan." Summary: This reverts commit 2c726dcf86bb176fb3695739a3d8bca2f95c41e6. Test Plan: build it Reviewed By: soren@fb.com Subscribers: woo, mathieubaudet, njormrod FB internal diff: D1575190 --- diff --git a/folly/SocketAddress.cpp b/folly/SocketAddress.cpp index 6c83e033..4834a134 100644 --- a/folly/SocketAddress.cpp +++ b/folly/SocketAddress.cpp @@ -201,11 +201,12 @@ void SocketAddress::setFromLocalAddress(int socket) { } void SocketAddress::setFromSockaddr(const struct sockaddr* address) { - uint16_t port; if (address->sa_family == AF_INET) { - port = ntohs(((sockaddr_in*)address)->sin_port); + storage_.addr = folly::IPAddress(address); + port_ = ntohs(((sockaddr_in*)address)->sin_port); } else if (address->sa_family == AF_INET6) { - port = ntohs(((sockaddr_in6*)address)->sin6_port); + storage_.addr = folly::IPAddress(address); + port_ = ntohs(((sockaddr_in6*)address)->sin6_port); } else if (address->sa_family == AF_UNIX) { // We need an explicitly specified length for AF_UNIX addresses, // to be able to distinguish anonymous addresses from addresses @@ -219,12 +220,7 @@ void SocketAddress::setFromSockaddr(const struct sockaddr* address) { "SocketAddress::setFromSockaddr() called " "with unsupported address type"); } - if (getFamily() == AF_UNIX) { - storage_.un.free(); - external_ = false; - } - storage_.addr = folly::IPAddress(address); - port_ = port; + external_ = false; } void SocketAddress::setFromSockaddr(const struct sockaddr* address, diff --git a/folly/small_vector.h b/folly/small_vector.h index 132ff241..92a5a2fc 100644 --- a/folly/small_vector.h +++ b/folly/small_vector.h @@ -391,16 +391,13 @@ public: try { std::uninitialized_copy(o.begin(), o.end(), begin()); } catch (...) { - if (this->isExtern()) { - u.freeHeap(); - } + if (this->isExtern()) u.freeHeap(); throw; } this->setSize(n); } - small_vector(small_vector&& o) - noexcept(std::is_nothrow_move_constructible::value) { + small_vector(small_vector&& o) { if (o.isExtern()) { swap(o); } else { @@ -880,31 +877,18 @@ private: auto distance = std::distance(first, last); makeSize(distance); this->setSize(distance); - try { - detail::populateMemForward(data(), distance, - [&] (void* p) { new (p) value_type(*first++); } - ); - } catch (...) { - if (this->isExtern()) { - u.freeHeap(); - } - throw; - } + + detail::populateMemForward(data(), distance, + [&] (void* p) { new (p) value_type(*first++); } + ); } void doConstruct(size_type n, value_type const& val) { makeSize(n); this->setSize(n); - try { - detail::populateMemForward(data(), n, - [&] (void* p) { new (p) value_type(val); } - ); - } catch (...) { - if (this->isExtern()) { - u.freeHeap(); - } - throw; - } + detail::populateMemForward(data(), n, + [&] (void* p) { new (p) value_type(val); } + ); } // The true_type means we should forward to the size_t,value_type diff --git a/folly/test/PackedSyncPtrTest.cpp b/folly/test/PackedSyncPtrTest.cpp index f926d6ff..adcc3504 100644 --- a/folly/test/PackedSyncPtrTest.cpp +++ b/folly/test/PackedSyncPtrTest.cpp @@ -61,7 +61,6 @@ TEST(PackedSyncPtr, Basic) { EXPECT_EQ(sp.extra(), 0x13); EXPECT_EQ(sp.get(), newP); sp.unlock(); - delete sp.get(); } // Here we use the PackedSyncPtr to lock the whole SyncVec (base, *base, and sz) @@ -69,7 +68,6 @@ template struct SyncVec { PackedSyncPtr base; SyncVec() { base.init(); } - ~SyncVec() { free(base.get()); } void push_back(const T& t) { base.set((T*) realloc(base.get(), (base.extra() + 1) * sizeof(T))); diff --git a/folly/test/ThreadLocalTest.cpp b/folly/test/ThreadLocalTest.cpp index e2911744..36917139 100644 --- a/folly/test/ThreadLocalTest.cpp +++ b/folly/test/ThreadLocalTest.cpp @@ -184,7 +184,7 @@ TEST(ThreadLocal, SimpleRepeatDestructor) { TEST(ThreadLocal, InterleavedDestructors) { Widget::totalVal_ = 0; - std::unique_ptr> w; + ThreadLocal* w = nullptr; int wVersion = 0; const int wVersionMax = 2; int thIter = 0; @@ -214,7 +214,8 @@ TEST(ThreadLocal, InterleavedDestructors) { { std::lock_guard g(lock); thIterPrev = thIter; - w.reset(new ThreadLocal()); + delete w; + w = new ThreadLocal(); ++wVersion; } while (true) {