Commit 3239f3c4 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook GitHub Bot

Fix a double delete issue

Summary: Fix a double delete issue

Reviewed By: danobi

Differential Revision: D25005179

fbshipit-source-id: 03ae8f0722316294979ec7511ef9ac794196a7ce
parent 8659ee3f
...@@ -310,11 +310,11 @@ IoUringBackend::IoUringBackend(Options options) ...@@ -310,11 +310,11 @@ IoUringBackend::IoUringBackend(Options options)
numEntries_ *= 2; numEntries_ *= 2;
// timer entry // timer entry
timerEntry_ = std::make_unique<IoSqe>(this, false); timerEntry_ = std::make_unique<IoSqe>(this, false, true /*persist*/);
timerEntry_->backendCb_ = PollIoBackend::processTimerIoCb; timerEntry_->backendCb_ = PollIoBackend::processTimerIoCb;
// signal entry // signal entry
signalReadEntry_ = std::make_unique<IoSqe>(this, false); signalReadEntry_ = std::make_unique<IoSqe>(this, false, true /*persist*/);
signalReadEntry_->backendCb_ = PollIoBackend::processSignalReadIoCb; signalReadEntry_->backendCb_ = PollIoBackend::processSignalReadIoCb;
// we need to call the init before adding the timer fd // we need to call the init before adding the timer fd
......
...@@ -128,8 +128,11 @@ class IoUringBackend : public PollIoBackend { ...@@ -128,8 +128,11 @@ class IoUringBackend : public PollIoBackend {
int submitBusyCheck(int num, WaitForEventsMode waitForEvents); int submitBusyCheck(int num, WaitForEventsMode waitForEvents);
struct IoSqe : public PollIoBackend::IoCb { struct IoSqe : public PollIoBackend::IoCb {
explicit IoSqe(PollIoBackend* backend = nullptr, bool poolAlloc = false) explicit IoSqe(
: PollIoBackend::IoCb(backend, poolAlloc) {} PollIoBackend* backend = nullptr,
bool poolAlloc = false,
bool persist = false)
: PollIoBackend::IoCb(backend, poolAlloc, persist) {}
~IoSqe() override = default; ~IoSqe() override = default;
void processSubmit(void* entry) override { void processSubmit(void* entry) override {
......
...@@ -358,7 +358,6 @@ PollIoBackend::IoCb* PollIoBackend::allocIoCb(const EventCallback& cb) { ...@@ -358,7 +358,6 @@ PollIoBackend::IoCb* PollIoBackend::allocIoCb(const EventCallback& cb) {
void PollIoBackend::releaseIoCb(PollIoBackend::IoCb* aioIoCb) { void PollIoBackend::releaseIoCb(PollIoBackend::IoCb* aioIoCb) {
CHECK_GT(numIoCbInUse_, 0); CHECK_GT(numIoCbInUse_, 0);
numIoCbInUse_--;
aioIoCb->cbData_.releaseData(); aioIoCb->cbData_.releaseData();
// unregister the file descriptor record // unregister the file descriptor record
if (aioIoCb->fdRecord_) { if (aioIoCb->fdRecord_) {
...@@ -367,10 +366,14 @@ void PollIoBackend::releaseIoCb(PollIoBackend::IoCb* aioIoCb) { ...@@ -367,10 +366,14 @@ void PollIoBackend::releaseIoCb(PollIoBackend::IoCb* aioIoCb) {
} }
if (FOLLY_LIKELY(aioIoCb->poolAlloc_)) { if (FOLLY_LIKELY(aioIoCb->poolAlloc_)) {
numIoCbInUse_--;
aioIoCb->event_ = nullptr; aioIoCb->event_ = nullptr;
freeList_.push_front(*aioIoCb); freeList_.push_front(*aioIoCb);
} else { } else {
delete aioIoCb; if (!aioIoCb->persist_) {
numIoCbInUse_--;
delete aioIoCb;
}
} }
} }
......
...@@ -152,8 +152,13 @@ class PollIoBackend : public EventBaseBackendBase { ...@@ -152,8 +152,13 @@ class PollIoBackend : public EventBaseBackendBase {
boost::intrusive::link_mode<boost::intrusive::auto_unlink>> { boost::intrusive::link_mode<boost::intrusive::auto_unlink>> {
using BackendCb = void(PollIoBackend*, IoCb*, int64_t); using BackendCb = void(PollIoBackend*, IoCb*, int64_t);
explicit IoCb(PollIoBackend* backend, bool poolAlloc = true) // persist are entries that do not go through the normal delete path if
: backend_(backend), poolAlloc_(poolAlloc) {} // not allocated from a pool
explicit IoCb(
PollIoBackend* backend,
bool poolAlloc = true,
bool persist = false)
: backend_(backend), poolAlloc_(poolAlloc), persist_(persist) {}
virtual ~IoCb() = default; virtual ~IoCb() = default;
virtual void processSubmit(void* entry) = 0; virtual void processSubmit(void* entry) = 0;
...@@ -163,6 +168,7 @@ class PollIoBackend : public EventBaseBackendBase { ...@@ -163,6 +168,7 @@ class PollIoBackend : public EventBaseBackendBase {
PollIoBackend* backend_; PollIoBackend* backend_;
BackendCb* backendCb_{nullptr}; BackendCb* backendCb_{nullptr};
const bool poolAlloc_; const bool poolAlloc_;
const bool persist_;
Event* event_{nullptr}; Event* event_{nullptr};
FdRegistrationRecord* fdRecord_{nullptr}; FdRegistrationRecord* fdRecord_{nullptr};
size_t useCount_{0}; size_t useCount_{0};
......
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