Skip to content

Commit c2a48c0

Browse files
committed
Fix memory leaks in Sections, Segments, Settings, ExternalLibrary, and BackgroundTask
1 parent e76bda2 commit c2a48c0

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

binaryview.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,7 +3835,7 @@ Ref<BackgroundTask> BinaryView::GetBackgroundAnalysisTask()
38353835
if (!task)
38363836
return nullptr;
38373837

3838-
return new BackgroundTask(BNNewBackgroundTaskReference(task));
3838+
return new BackgroundTask(task);
38393839
}
38403840

38413841

@@ -4954,7 +4954,7 @@ Ref<Segment> BinaryView::GetSegmentAt(uint64_t addr)
49544954
if (!segment)
49554955
return nullptr;
49564956

4957-
return new Segment(BNNewSegmentReference(segment));
4957+
return new Segment(segment);
49584958
}
49594959

49604960

@@ -5043,7 +5043,7 @@ Ref<Section> BinaryView::GetSectionByName(const string& name)
50435043
{
50445044
BNSection* section = BNGetSectionByName(m_object, name.c_str());
50455045
if (section)
5046-
return new Section(BNNewSectionReference(section));
5046+
return new Section(section);
50475047
return nullptr;
50485048
}
50495049

@@ -5386,7 +5386,7 @@ Ref<ExternalLibrary> BinaryView::AddExternalLibrary(const std::string& name, Ref
53865386
BNExternalLibrary* lib = BNBinaryViewAddExternalLibrary(m_object, name.c_str(), backingFile ? backingFile->m_object : nullptr, isAuto);
53875387
if (!lib)
53885388
return nullptr;
5389-
return new ExternalLibrary(BNNewExternalLibraryReference(lib));
5389+
return new ExternalLibrary(lib);
53905390
}
53915391

53925392

externallibrary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Ref<ExternalLibrary> ExternalLocation::GetExternalLibrary()
9292
BNExternalLibrary* lib = BNExternalLocationGetExternalLibrary(m_object);
9393
if (!lib)
9494
return nullptr;
95-
return new ExternalLibrary(BNNewExternalLibraryReference(lib));
95+
return new ExternalLibrary(lib);
9696
}
9797

9898

python/binaryview.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9545,9 +9545,7 @@ def get_segment_at(self, addr: int) -> Optional[Segment]:
95459545
seg = core.BNGetSegmentAt(self.handle, addr)
95469546
if not seg:
95479547
return None
9548-
segment_handle = core.BNNewSegmentReference(seg)
9549-
assert segment_handle is not None, "core.BNNewSegmentReference returned None"
9550-
return Segment(segment_handle)
9548+
return Segment(seg)
95519549

95529550
def get_address_for_data_offset(self, offset: int) -> Optional[int]:
95539551
"""
@@ -9639,9 +9637,7 @@ def get_section_by_name(self, name: str) -> Optional[Section]:
96399637
section = core.BNGetSectionByName(self.handle, name)
96409638
if section is None:
96419639
return None
9642-
section_handle = core.BNNewSectionReference(section)
9643-
assert section_handle is not None, "core.BNNewSectionReference returned None"
9644-
result = Section(section_handle)
9640+
result = Section(section)
96459641
return result
96469642

96479643
def get_unique_section_names(self, name_list: List[str]) -> List[str]:

settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using namespace std;
77

88
Settings::Settings(BNSettings* settings)
99
{
10-
m_object = BNNewSettingsReference(settings);
10+
m_object = settings;
1111
}
1212

1313

0 commit comments

Comments
 (0)