Skip to content

Commit ebb6bb7

Browse files
committed
[lldb/python] Plug SBStructuredData leaks
This applies the from D114259 to the SBStructuredData class.
1 parent fb47725 commit ebb6bb7

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed

lldb/bindings/python/python-swigsafecast.swig

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ PyObject *SBTypeToSWIGWrapper(lldb::SBTypeSummaryOptions &summary_options_sb) {
4141
SWIGTYPE_p_lldb__SBTypeSummaryOptions, 0);
4242
}
4343

44-
PyObject *SBTypeToSWIGWrapper(lldb::SBStructuredData &structured_data_sb) {
45-
return SWIG_NewPointerObj(&structured_data_sb,
46-
SWIGTYPE_p_lldb__SBStructuredData, 0);
47-
}
48-
4944
PyObject *SBTypeToSWIGWrapper(lldb::SBSymbolContext &sym_ctx_sb) {
5045
return SWIG_NewPointerObj(&sym_ctx_sb, SWIGTYPE_p_lldb__SBSymbolContext, 0);
5146
}
@@ -86,5 +81,13 @@ PythonObject ToSWIGWrapper(lldb::BreakpointSP breakpoint_sp) {
8681
SWIGTYPE_p_lldb__SBBreakpoint);
8782
}
8883

84+
PythonObject ToSWIGWrapper(std::unique_ptr<lldb::SBStructuredData> data_sb) {
85+
return ToSWIGHelper(data_sb.release(), SWIGTYPE_p_lldb__SBStructuredData);
86+
}
87+
88+
PythonObject ToSWIGWrapper(const StructuredDataImpl &data_impl) {
89+
return ToSWIGWrapper(std::make_unique<lldb::SBStructuredData>(data_impl));
90+
}
91+
8992
} // namespace python
9093
} // namespace lldb_private

lldb/bindings/python/python-wrapper.swig

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,9 @@ lldb_private::LLDBSwigPythonBreakpointCallbackFunction
5252

5353
auto result = [&] () -> Expected<PythonObject> {
5454
// If the called function doesn't take extra_args, drop them here:
55-
if (max_positional_args < 4) {
55+
if (max_positional_args < 4)
5656
return pfunc.Call(frame_arg, bp_loc_arg, dict);
57-
} else {
58-
// FIXME: SBStructuredData leaked here
59-
lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
60-
PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_value));
61-
return pfunc.Call(frame_arg, bp_loc_arg, args_arg, dict);
62-
}
57+
return pfunc.Call(frame_arg, bp_loc_arg, ToSWIGWrapper(args_impl), dict);
6358
} ();
6459

6560
if (!result)
@@ -289,11 +284,7 @@ lldb_private::LLDBSwigPythonCreateScriptedProcess
289284

290285
PythonObject result = {};
291286
if (arg_info.get().max_positional_args == 2) {
292-
// FIXME: SBStructuredData leaked here
293-
PythonObject args_arg(
294-
PyRefType::Owned,
295-
SBTypeToSWIGWrapper(*new lldb::SBStructuredData(args_impl)));
296-
result = pfunc(target_arg, args_arg);
287+
result = pfunc(target_arg, ToSWIGWrapper(args_impl));
297288
} else {
298289
error_string.assign("wrong number of arguments in __init__, should be 2 (not including self)");
299290
Py_RETURN_NONE;
@@ -343,11 +334,7 @@ lldb_private::LLDBSwigPythonCreateScriptedThread
343334

344335
PythonObject result = {};
345336
if (arg_info.get().max_positional_args == 2) {
346-
// FIXME: SBStructuredData leaked here
347-
PythonObject args_arg(
348-
PyRefType::Owned,
349-
SBTypeToSWIGWrapper(*new lldb::SBStructuredData(args_impl)));
350-
result = pfunc(ToSWIGWrapper(process_sp), args_arg);
337+
result = pfunc(ToSWIGWrapper(process_sp), ToSWIGWrapper(args_impl));
351338
} else {
352339
error_string.assign("wrong number of arguments in __init__, should be 2 (not including self)");
353340
Py_RETURN_NONE;
@@ -399,17 +386,15 @@ lldb_private::LLDBSwigPythonCreateScriptedThreadPlan
399386
}
400387

401388
PythonObject result = {};
402-
// FIXME: SBStructuredData leaked here
403-
auto *args_sb = new lldb::SBStructuredData(args_impl);
389+
auto args_sb = std::make_unique<lldb::SBStructuredData>(args_impl);
404390
if (arg_info.get().max_positional_args == 2) {
405391
if (args_sb->IsValid()) {
406392
error_string.assign("args passed, but __init__ does not take an args dictionary");
407393
Py_RETURN_NONE;
408394
}
409395
result = pfunc(tp_arg, dict);
410396
} else if (arg_info.get().max_positional_args >= 3) {
411-
PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_sb));
412-
result = pfunc(tp_arg, args_arg, dict);
397+
result = pfunc(tp_arg, ToSWIGWrapper(std::move(args_sb)), dict);
413398
} else {
414399
error_string.assign("wrong number of arguments in __init__, should be 2 or 3 (not including self)");
415400
Py_RETURN_NONE;
@@ -486,11 +471,8 @@ void *lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
486471
if (!pfunc.IsAllocated())
487472
return nullptr;
488473

489-
// FIXME: SBStructuredData leaked here
490-
lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
491-
PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_value));
492-
493-
PythonObject result = pfunc(ToSWIGWrapper(breakpoint_sp), args_arg, dict);
474+
PythonObject result =
475+
pfunc(ToSWIGWrapper(breakpoint_sp), ToSWIGWrapper(args_impl), dict);
494476
// FIXME: At this point we should check that the class we found supports all the methods
495477
// that we need.
496478

@@ -591,11 +573,8 @@ lldb_private::LLDBSwigPythonCreateScriptedStopHook
591573
return nullptr;
592574
}
593575

594-
// FIXME: SBStructuredData leaked here
595-
lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
596-
PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_value));
597-
598-
PythonObject result = pfunc(ToSWIGWrapper(target_sp), args_arg, dict);
576+
PythonObject result =
577+
pfunc(ToSWIGWrapper(target_sp), ToSWIGWrapper(args_impl), dict);
599578

600579
if (result.IsAllocated())
601580
{

0 commit comments

Comments
 (0)