summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2021-11-26 09:46:31 +0100
committerPavel Labath <pavel@labath.sk>2021-12-14 17:02:24 +0100
commitebb6bb725eadd57a0f7995fff17774020f6f0389 (patch)
tree5bb7ba0a211f671b0d927faa1dac18e073978828
parentfb47725d1417f48898b7628c58e54c6a02754bf0 (diff)
downloadllvm-ebb6bb725eadd57a0f7995fff17774020f6f0389.tar.gz
[lldb/python] Plug SBStructuredData leaks
This applies the from D114259 to the SBStructuredData class.
-rw-r--r--lldb/bindings/python/python-swigsafecast.swig13
-rw-r--r--lldb/bindings/python/python-wrapper.swig41
2 files changed, 18 insertions, 36 deletions
diff --git a/lldb/bindings/python/python-swigsafecast.swig b/lldb/bindings/python/python-swigsafecast.swig
index fdd3b4e62c10..87abe0b3f187 100644
--- a/lldb/bindings/python/python-swigsafecast.swig
+++ b/lldb/bindings/python/python-swigsafecast.swig
@@ -41,11 +41,6 @@ PyObject *SBTypeToSWIGWrapper(lldb::SBTypeSummaryOptions &summary_options_sb) {
SWIGTYPE_p_lldb__SBTypeSummaryOptions, 0);
}
-PyObject *SBTypeToSWIGWrapper(lldb::SBStructuredData &structured_data_sb) {
- return SWIG_NewPointerObj(&structured_data_sb,
- SWIGTYPE_p_lldb__SBStructuredData, 0);
-}
-
PyObject *SBTypeToSWIGWrapper(lldb::SBSymbolContext &sym_ctx_sb) {
return SWIG_NewPointerObj(&sym_ctx_sb, SWIGTYPE_p_lldb__SBSymbolContext, 0);
}
@@ -86,5 +81,13 @@ PythonObject ToSWIGWrapper(lldb::BreakpointSP breakpoint_sp) {
SWIGTYPE_p_lldb__SBBreakpoint);
}
+PythonObject ToSWIGWrapper(std::unique_ptr<lldb::SBStructuredData> data_sb) {
+ return ToSWIGHelper(data_sb.release(), SWIGTYPE_p_lldb__SBStructuredData);
+}
+
+PythonObject ToSWIGWrapper(const StructuredDataImpl &data_impl) {
+ return ToSWIGWrapper(std::make_unique<lldb::SBStructuredData>(data_impl));
+}
+
} // namespace python
} // namespace lldb_private
diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig
index da943f73c435..f1cf8c8e09d7 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -52,14 +52,9 @@ lldb_private::LLDBSwigPythonBreakpointCallbackFunction
auto result = [&] () -> Expected<PythonObject> {
// If the called function doesn't take extra_args, drop them here:
- if (max_positional_args < 4) {
+ if (max_positional_args < 4)
return pfunc.Call(frame_arg, bp_loc_arg, dict);
- } else {
- // FIXME: SBStructuredData leaked here
- lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
- PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_value));
- return pfunc.Call(frame_arg, bp_loc_arg, args_arg, dict);
- }
+ return pfunc.Call(frame_arg, bp_loc_arg, ToSWIGWrapper(args_impl), dict);
} ();
if (!result)
@@ -289,11 +284,7 @@ lldb_private::LLDBSwigPythonCreateScriptedProcess
PythonObject result = {};
if (arg_info.get().max_positional_args == 2) {
- // FIXME: SBStructuredData leaked here
- PythonObject args_arg(
- PyRefType::Owned,
- SBTypeToSWIGWrapper(*new lldb::SBStructuredData(args_impl)));
- result = pfunc(target_arg, args_arg);
+ result = pfunc(target_arg, ToSWIGWrapper(args_impl));
} else {
error_string.assign("wrong number of arguments in __init__, should be 2 (not including self)");
Py_RETURN_NONE;
@@ -343,11 +334,7 @@ lldb_private::LLDBSwigPythonCreateScriptedThread
PythonObject result = {};
if (arg_info.get().max_positional_args == 2) {
- // FIXME: SBStructuredData leaked here
- PythonObject args_arg(
- PyRefType::Owned,
- SBTypeToSWIGWrapper(*new lldb::SBStructuredData(args_impl)));
- result = pfunc(ToSWIGWrapper(process_sp), args_arg);
+ result = pfunc(ToSWIGWrapper(process_sp), ToSWIGWrapper(args_impl));
} else {
error_string.assign("wrong number of arguments in __init__, should be 2 (not including self)");
Py_RETURN_NONE;
@@ -399,8 +386,7 @@ lldb_private::LLDBSwigPythonCreateScriptedThreadPlan
}
PythonObject result = {};
- // FIXME: SBStructuredData leaked here
- auto *args_sb = new lldb::SBStructuredData(args_impl);
+ auto args_sb = std::make_unique<lldb::SBStructuredData>(args_impl);
if (arg_info.get().max_positional_args == 2) {
if (args_sb->IsValid()) {
error_string.assign("args passed, but __init__ does not take an args dictionary");
@@ -408,8 +394,7 @@ lldb_private::LLDBSwigPythonCreateScriptedThreadPlan
}
result = pfunc(tp_arg, dict);
} else if (arg_info.get().max_positional_args >= 3) {
- PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_sb));
- result = pfunc(tp_arg, args_arg, dict);
+ result = pfunc(tp_arg, ToSWIGWrapper(std::move(args_sb)), dict);
} else {
error_string.assign("wrong number of arguments in __init__, should be 2 or 3 (not including self)");
Py_RETURN_NONE;
@@ -486,11 +471,8 @@ void *lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
if (!pfunc.IsAllocated())
return nullptr;
- // FIXME: SBStructuredData leaked here
- lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
- PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_value));
-
- PythonObject result = pfunc(ToSWIGWrapper(breakpoint_sp), args_arg, dict);
+ PythonObject result =
+ pfunc(ToSWIGWrapper(breakpoint_sp), ToSWIGWrapper(args_impl), dict);
// FIXME: At this point we should check that the class we found supports all the methods
// that we need.
@@ -591,11 +573,8 @@ lldb_private::LLDBSwigPythonCreateScriptedStopHook
return nullptr;
}
- // FIXME: SBStructuredData leaked here
- lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
- PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_value));
-
- PythonObject result = pfunc(ToSWIGWrapper(target_sp), args_arg, dict);
+ PythonObject result =
+ pfunc(ToSWIGWrapper(target_sp), ToSWIGWrapper(args_impl), dict);
if (result.IsAllocated())
{