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