diff --git a/common/ZeroCopyReturnValue.cpp b/common/ZeroCopyReturnValue.cpp index 984b9082..b5d88011 100644 --- a/common/ZeroCopyReturnValue.cpp +++ b/common/ZeroCopyReturnValue.cpp @@ -32,8 +32,10 @@ void ZeroCopyReturnValue::release() { ReadyToSend(); if (status == ImageBufferEntryStatus::Sending) { - buf_ctrl.ReleaseSlot(handle); + // Reset before releasing: ReleaseSlot puts the handle back on the free list, after which + // another thread can take this same object out of GetImageSlot() and read status. status = ImageBufferEntryStatus::InPreparation; + buf_ctrl.ReleaseSlot(handle); } else { throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Trying to send image that is not in preparation");