Skip to content

Commit 695cb9e

Browse files
committed
[MERGE #979] FreeLoopBodyJobs race condition.
Merge pull request #979 from LouisLaf:stackjob FreeLoopBodyJobs also need a processed flag to avoid race conditions. To free data associated with a JIT loopbody, we create a FreeLoopBodyJob. If we can't allocate one of these (OOM), we create one on the stack, and wait for it to be processed. There was a race condition if we processed the job before starting to wait for it... The 'processed' flag avoids this.
2 parents 5f5a76c + 2414b30 commit 695cb9e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/Backend/NativeCodeGenerator.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ void SetProfileMode(BOOL fSet);
211211
: JsUtil::WaitableJobManager(processor)
212212
, autoClose(true)
213213
, isClosed(false)
214+
, processed(false)
214215
{
215216
Processor()->AddManager(this);
216217
}
@@ -238,7 +239,7 @@ void SetProfileMode(BOOL fSet);
238239

239240
FreeLoopBodyJob* GetJob(FreeLoopBodyJob* job)
240241
{
241-
return job;
242+
return this->processed ? nullptr : job;
242243
}
243244

244245
bool WasAddedToJobProcessor(JsUtil::Job *const job) const
@@ -268,6 +269,8 @@ void SetProfileMode(BOOL fSet);
268269
{
269270
FreeLoopBodyJob* freeLoopBodyJob = static_cast<FreeLoopBodyJob*>(job);
270271

272+
this->processed = true;
273+
271274
if (freeLoopBodyJob->heapAllocated)
272275
{
273276
HeapDelete(freeLoopBodyJob);
@@ -280,6 +283,7 @@ void SetProfileMode(BOOL fSet);
280283
NativeCodeGenerator* nativeCodeGen;
281284
bool autoClose;
282285
bool isClosed;
286+
bool processed;
283287
};
284288

285289
FreeLoopBodyJobManager freeLoopBodyManager;

0 commit comments

Comments
 (0)