From 01ebe8a5f7e3902fe2c58eaaf3fd712697849997 Mon Sep 17 00:00:00 2001 From: anand76 Date: Sun, 18 Sep 2022 19:00:48 -0700 Subject: [PATCH] Fix invalid reference in MultiGet due to vector resizing (#10702) Summary: Fix invalid reference in MultiGet due to resizing of the ```batches``` autovector. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10702 Test Plan: Run asan crash test Reviewed By: riversand963 Differential Revision: D39608753 Pulled By: anand1976 fbshipit-source-id: 7a9e7fc6f436f08eb22003d0e6b0e1e4dcdc1a2a --- db/version_set.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/db/version_set.cc b/db/version_set.cc index 2a8d958d0..c656cd547 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -2776,6 +2776,11 @@ Status Version::MultiGetAsync( to_process.emplace_back(0); while (!to_process.empty()) { + // As we process a batch, it may get split into two. So reserve space for + // an additional batch in the autovector in order to prevent later moves + // of elements in ProcessBatch(). + batches.reserve(batches.size() + 1); + size_t idx = to_process.front(); FilePickerMultiGet* batch = &batches.at(idx); unsigned int num_tasks_queued = 0;