diff options
author | Alberto Compagno <acompagn+fdio@cisco.com> | 2019-02-13 15:06:23 +0100 |
---|---|---|
committer | Alberto Compagno <acompagn+fdio@cisco.com> | 2019-02-13 15:06:23 +0100 |
commit | d1dedcb21e7ba074a0a83fad09a742e54a8d1525 (patch) | |
tree | 31aebff80bf016d32480a1e38b3e58110f8adb67 /libtransport/src/hicn/transport/utils | |
parent | 13fccc2bb1c2317061e6bf985c87bca647fb3b6f (diff) |
[HICN-60] Solved concurrent memory access which was leading to seg-fault
Change-Id: I7b9fcf79bb97650346f7d92af8cbb419f0a5cb95
Signed-off-by: Alberto Compagno <acompagn+fdio@cisco.com>
Diffstat (limited to 'libtransport/src/hicn/transport/utils')
-rw-r--r-- | libtransport/src/hicn/transport/utils/epoll_event_reactor.cc | 10 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/utils/object_pool.h | 1 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/utils/ring_buffer.h | 2 |
3 files changed, 6 insertions, 7 deletions
diff --git a/libtransport/src/hicn/transport/utils/epoll_event_reactor.cc b/libtransport/src/hicn/transport/utils/epoll_event_reactor.cc index 81b471857..6df9e5656 100644 --- a/libtransport/src/hicn/transport/utils/epoll_event_reactor.cc +++ b/libtransport/src/hicn/transport/utils/epoll_event_reactor.cc @@ -51,10 +51,9 @@ int EpollEventReactor::addFileDescriptor(int fd, uint32_t events) { int EpollEventReactor::addFileDescriptor(int fd, uint32_t events, EventCallback &callback) { auto it = event_callback_map_.find(fd); - event_callback_map_[fd] = callback; - if (it != event_callback_map_.end()) { + + if (it == event_callback_map_.end()) { event_callback_map_[fd] = callback; - } else { return addFileDescriptor(fd, events); } @@ -64,10 +63,9 @@ int EpollEventReactor::addFileDescriptor(int fd, uint32_t events, int EpollEventReactor::addFileDescriptor(int fd, uint32_t events, EventCallback &&callback) { auto it = event_callback_map_.find(fd); - event_callback_map_[fd] = callback; - if (it != event_callback_map_.end()) { + + if (it == event_callback_map_.end()) { event_callback_map_[fd] = callback; - } else { return addFileDescriptor(fd, events); } diff --git a/libtransport/src/hicn/transport/utils/object_pool.h b/libtransport/src/hicn/transport/utils/object_pool.h index 9fda214cd..e34730e81 100644 --- a/libtransport/src/hicn/transport/utils/object_pool.h +++ b/libtransport/src/hicn/transport/utils/object_pool.h @@ -62,6 +62,7 @@ class ObjectPool { void add(T *object) { utils::SpinLock::Acquire locked(object_pool_lock_); + if (TRANSPORT_EXPECT_TRUE(!destructor_)) { object_pool_.emplace_back(makePtr(object)); } diff --git a/libtransport/src/hicn/transport/utils/ring_buffer.h b/libtransport/src/hicn/transport/utils/ring_buffer.h index 52bcd81c4..9babe56bd 100644 --- a/libtransport/src/hicn/transport/utils/ring_buffer.h +++ b/libtransport/src/hicn/transport/utils/ring_buffer.h @@ -86,7 +86,7 @@ bool CircularFifo<Element, Size>::push(Element&& item) { // the tail must be accessed with at least acquire template <typename Element, std::size_t Size> bool CircularFifo<Element, Size>::pop(Element& item) { - const auto current_head = head_.load(std::memory_order_relaxed); + const size_t current_head = head_.load(std::memory_order_relaxed); if (current_head == tail_.load(std::memory_order_acquire)) { return false; // empty queue } |