[Lldb-commits] [lldb] [lldb] Implement PluginInfo move constructor (PR #185137)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Fri Mar 6 15:49:31 PST 2026
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/185137
The default move constructor wasn't nulling out the callbacks. Combined with the fact that llvm::sys::DynamicLibrary has no explicit move constructor and hence library.isValid() still returned true after having moved-from, we would end up calling plugin_term_callback() when destroying the moved-from PluginInfo, calling it prematurely.
>From a36f65c9d8832d232bf31e749a6452ed4677d947 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Fri, 6 Mar 2026 15:42:58 -0800
Subject: [PATCH] [lldb] Implement PluginInfo move constructor
The default move constructor wasn't nulling out the callbacks. Combined
with the fact that llvm::sys::DynamicLibrary has no explicit move
constructor and hence library.isValid() still returned true after having
moved-from, we would end up calling plugin_term_callback() when
destroying the moved-from PluginInfo, calling it prematurely.
---
lldb/source/Core/PluginManager.cpp | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp
index 430c9131ee6be..91dd2dac0dcaa 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -46,8 +46,19 @@ struct PluginInfo {
PluginInfo(const PluginInfo &) = delete;
PluginInfo &operator=(const PluginInfo &) = delete;
- PluginInfo(PluginInfo &&) = default;
- PluginInfo &operator=(PluginInfo &&) = default;
+ PluginInfo(PluginInfo &&other)
+ : library(std::move(other.library)),
+ plugin_init_callback(
+ std::exchange(other.plugin_init_callback, nullptr)),
+ plugin_term_callback(
+ std::exchange(other.plugin_term_callback, nullptr)) {}
+
+ PluginInfo &operator=(PluginInfo &&other) {
+ library = std::move(other.library);
+ plugin_init_callback = std::exchange(other.plugin_init_callback, nullptr);
+ plugin_term_callback = std::exchange(other.plugin_term_callback, nullptr);
+ return *this;
+ }
~PluginInfo() {
if (!library.isValid())
More information about the lldb-commits
mailing list