Skip to content

Commit 5ba2103

Browse files
committed
[fix][blockaccess] Fix coredump when wrapper destory
1 parent 99b29d4 commit 5ba2103

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/blockaccess/block_accesser.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <absl/strings/str_format.h>
2121

2222
#include <memory>
23+
#include <utility>
2324

2425
#include "blockaccess/block_access_log.h"
2526
#include "blockaccess/rados/rados_accesser.h"
@@ -138,10 +139,10 @@ void BlockAccesserImpl::AsyncPut(
138139
int64_t start_us = butil::cpuwide_time_us();
139140
block_put_async_num << 1;
140141

141-
auto origin_cb = context->cb;
142+
auto origin_cb = std::move(context->cb);
142143

143-
context->cb = [this, start_us,
144-
origin_cb](const std::shared_ptr<PutObjectAsyncContext>& ctx) {
144+
context->cb = [this, start_us, origin = std::move(origin_cb)](
145+
const std::shared_ptr<PutObjectAsyncContext>& ctx) {
145146
BlockAccessLogGuard log(start_us, [&]() {
146147
return fmt::format("async_put_block ({}, {}) : {}", ctx->key,
147148
ctx->buffer_size, ctx->status.ToString());
@@ -153,7 +154,7 @@ void BlockAccesserImpl::AsyncPut(
153154
inflight_bytes_throttle_->OnComplete(ctx->buffer_size);
154155

155156
// NOTE: this is necessary because caller reuse context when retry
156-
ctx->cb = origin_cb;
157+
ctx->cb = origin;
157158
ctx->cb(ctx);
158159
};
159160

@@ -191,10 +192,10 @@ void BlockAccesserImpl::AsyncGet(
191192
int64_t start_us = butil::cpuwide_time_us();
192193
block_get_async_num << 1;
193194

194-
auto origin_cb = context->cb;
195+
auto origin_cb = std::move(context->cb);
195196

196-
context->cb = [this, start_us,
197-
origin_cb](const std::shared_ptr<GetObjectAsyncContext>& ctx) {
197+
context->cb = [this, start_us, origin = std::move(origin_cb)](
198+
const std::shared_ptr<GetObjectAsyncContext>& ctx) {
198199
BlockAccessLogGuard log(start_us, [&]() {
199200
return fmt::format("async_get_block ({}, {}, {}) : {}", ctx->key,
200201
ctx->offset, ctx->len, ctx->status.ToString());
@@ -206,8 +207,8 @@ void BlockAccesserImpl::AsyncGet(
206207
inflight_bytes_throttle_->OnComplete(ctx->len);
207208

208209
// NOTE: this is necessary because caller reuse context when retry
209-
ctx->cb = origin_cb;
210-
origin_cb(ctx);
210+
ctx->cb = origin;
211+
ctx->cb(ctx);
211212
};
212213

213214
if (throttle_) {

0 commit comments

Comments
 (0)