From 71d6d9f86844746f36307d10e4eb422f30a69348 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Mon, 2 Jan 2023 11:01:19 +0300 Subject: [PATCH] Fix possible crash on ENOSPC during operation cancel in blockstore --- src/blockstore_impl.cpp | 1 + src/blockstore_write.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/blockstore_impl.cpp b/src/blockstore_impl.cpp index 76ec6645..5a4e9a9b 100644 --- a/src/blockstore_impl.cpp +++ b/src/blockstore_impl.cpp @@ -193,6 +193,7 @@ void blockstore_impl_t::loop() } if (wr_st == 2) { + submit_queue[op_idx] = NULL; new_idx--; } if (wr_st == 0) diff --git a/src/blockstore_write.cpp b/src/blockstore_write.cpp index 689b5d8d..ad714208 100644 --- a/src/blockstore_write.cpp +++ b/src/blockstore_write.cpp @@ -182,9 +182,15 @@ void blockstore_impl_t::cancel_all_writes(blockstore_op_t *op, blockstore_dirty_ bool found = false; for (auto other_op: submit_queue) { - // may be present in queue multiple times due to moving operations in submit_queue - if (other_op == op) + if (!other_op) + { + // freed operations during submitting are zeroed + } + else if (other_op == op) + { + // may be present in queue multiple times due to moving operations in submit_queue found = true; + } else if (found && other_op->oid == op->oid && (other_op->opcode == BS_OP_WRITE || other_op->opcode == BS_OP_WRITE_STABLE)) {