Skip to content

Commit 0486df2

Browse files
committed
try to prevent dangling reference access
1 parent bada40f commit 0486df2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Storages/MergeTree/ExportPartitionManifestUpdatingTask.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,17 @@ void ExportPartitionManifestUpdatingTask::poll()
131131
if (!cleanup_lock && has_local_entry_and_is_up_to_date)
132132
continue;
133133

134-
auto status_watch_callback = std::make_shared<Coordination::WatchCallback>([this, key](const Coordination::WatchResponse &) {
135-
storage.export_merge_tree_partition_manifest_updater->addStatusChange(key);
136-
storage.export_merge_tree_partition_status_handling_task->schedule();
134+
std::weak_ptr<ExportPartitionManifestUpdatingTask> weak_manifest_updater = storage.export_merge_tree_partition_manifest_updater;
135+
136+
auto status_watch_callback = std::make_shared<Coordination::WatchCallback>([weak_manifest_updater, key](const Coordination::WatchResponse &)
137+
{
138+
/// If the table is dropped but the watch is not removed, we need to prevent use after free
139+
/// below code assumes that if manifest updater is still alive, the status handling task is also alive
140+
if (auto manifest_updater = weak_manifest_updater.lock())
141+
{
142+
manifest_updater->addStatusChange(key);
143+
manifest_updater->storage.export_merge_tree_partition_status_handling_task->schedule();
144+
}
137145
});
138146

139147
std::string status;

0 commit comments

Comments
 (0)