common: reset the slot status before putting it back on the free list

release() published the handle through ReleaseSlot and only then wrote
status = InPreparation. ReleaseSlot makes the handle available to
GetImageSlot immediately, and GetImageSlot hands back this very object
without resetting it, so the receiver could observe the stale Sending
status and throw "Trying to send image that is not in preparation",
aborting the collection - or take the opposite interleaving and leak the
slot.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-31 14:41:13 +02:00
co-authored by Claude Opus 5
parent 433370f648
commit 89208697cb
+3 -1
View File
@@ -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");