From 9928562dadcbaa336049c08c9653d8f14f9bd05c Mon Sep 17 00:00:00 2001 From: John Sully Date: Fri, 17 Jul 2020 21:02:51 +0000 Subject: [PATCH] Fix lock after free in module API Former-commit-id: d88fd1588d292bffc0aa53c299cb52e7a4e91015 --- src/ae.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ae.cpp b/src/ae.cpp index 44f302e69..789a6888b 100644 --- a/src/ae.cpp +++ b/src/ae.cpp @@ -258,9 +258,11 @@ int aeCreateRemoteFileEvent(aeEventLoop *eventLoop, int fd, int mask, if (fSynchronous) { + { std::unique_lock ulock(cmd.pctl->mutexcv, std::adopt_lock); cmd.pctl->cv.wait(ulock); ret = cmd.pctl->rval; + } delete cmd.pctl; } @@ -300,7 +302,7 @@ int aePostFunction(aeEventLoop *eventLoop, std::function fn, bool fSynch cmd.fLock = fLock; if (fSynchronous) { - cmd.pctl = new (MALLOC_LOCAL) aeCommandControl(); + cmd.pctl = new (MALLOC_LOCAL) aeCommandControl; cmd.pctl->mutexcv.lock(); } @@ -311,9 +313,11 @@ int aePostFunction(aeEventLoop *eventLoop, std::function fn, bool fSynch int ret = AE_OK; if (fSynchronous) { + { std::unique_lock ulock(cmd.pctl->mutexcv, std::adopt_lock); cmd.pctl->cv.wait(ulock); ret = cmd.pctl->rval; + } delete cmd.pctl; } return ret;