[Lldb-commits] [lldb] bd1f29d - [lldb] Make SBCommandReturnObjectImpl copies owned (#230196)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 13 23:51:33 PDT 2026
Author: Fabrice de Gans
Date: 2026-10-14T06:51:26Z
New Revision: bd1f29da65a6009b07246f5aaeec27478f09478e
URL: https://github.com/llvm/llvm-project/commit/bd1f29da65a6009b07246f5aaeec27478f09478e
DIFF: https://github.com/llvm/llvm-project/commit/bd1f29da65a6009b07246f5aaeec27478f09478e.diff
LOG: [lldb] Make SBCommandReturnObjectImpl copies owned (#230196)
Copying an `SBCommandReturnObject` that wraps a `CommandReturnObject` it
does not own allocated a new `CommandReturnObject` but copied the
`m_owned` property set to false from the source. As a result, the new
object was never freed.
This also fixes the implementation of the copy assignment operator to
not cause a stack overflow by recursively calling into itself.
Added:
Modified:
lldb/source/API/SBCommandReturnObject.cpp
lldb/source/API/SBCommandReturnObjectImpl.h
Removed:
################################################################################
diff --git a/lldb/source/API/SBCommandReturnObject.cpp b/lldb/source/API/SBCommandReturnObject.cpp
index b63f91e9712f4..cd9bbad31c8b0 100644
--- a/lldb/source/API/SBCommandReturnObject.cpp
+++ b/lldb/source/API/SBCommandReturnObject.cpp
@@ -22,24 +22,28 @@
#include "lldb/Utility/Instrumentation.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-forward.h"
+#include <utility>
using namespace lldb;
using namespace lldb_private;
SBCommandReturnObjectImpl::SBCommandReturnObjectImpl()
- : m_ptr(new CommandReturnObject(false)) {}
+ : m_ptr(new CommandReturnObject(false)), m_owned(true) {}
SBCommandReturnObjectImpl::SBCommandReturnObjectImpl(CommandReturnObject &ref)
: m_ptr(&ref), m_owned(false) {}
SBCommandReturnObjectImpl::SBCommandReturnObjectImpl(
const SBCommandReturnObjectImpl &rhs)
- : m_ptr(new CommandReturnObject(*rhs.m_ptr)), m_owned(rhs.m_owned) {}
+ : m_ptr(new CommandReturnObject(*rhs.m_ptr)), m_owned(true) {}
SBCommandReturnObjectImpl &
SBCommandReturnObjectImpl::operator=(const SBCommandReturnObjectImpl &rhs) {
+ // After the copy-and-swap, `copy` holds the previous state of `this`.
+ // `copy` will be destroyed when it goes out of scope.
SBCommandReturnObjectImpl copy(rhs);
- std::swap(*this, copy);
+ std::swap(this->m_ptr, copy.m_ptr);
+ std::swap(this->m_owned, copy.m_owned);
return *this;
}
diff --git a/lldb/source/API/SBCommandReturnObjectImpl.h b/lldb/source/API/SBCommandReturnObjectImpl.h
index e0a90bd1e12bd..fe6c74a534d0b 100644
--- a/lldb/source/API/SBCommandReturnObjectImpl.h
+++ b/lldb/source/API/SBCommandReturnObjectImpl.h
@@ -24,7 +24,7 @@ class SBCommandReturnObjectImpl {
private:
CommandReturnObject *m_ptr;
- bool m_owned = true;
+ bool m_owned;
};
} // namespace lldb_private
More information about the lldb-commits
mailing list