Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions python/binaryview.py
Original file line number Diff line number Diff line change
Expand Up @@ -9200,15 +9200,16 @@ def import_library_type(self, name: str, lib: Optional[typelibrary.TypeLibrary]
:rtype: Type
"""
_name = _types.QualifiedName(name)
_lib = ctypes.POINTER(ctypes.POINTER(core.BNTypeLibrary))()
_lib = ctypes.POINTER(core.BNTypeLibrary)()
if lib is not None:
_lib.contents = lib.handle
else:
_lib.contents = ctypes.POINTER(core.BNTypeLibrary)()
_lib = ctypes.cast(lib.handle, ctypes.POINTER(core.BNTypeLibrary))

handle = core.BNBinaryViewImportTypeLibraryType(
self.handle, _lib, _name._to_core_struct()
self.handle, ctypes.byref(_lib), _name._to_core_struct()
)
# Core stores a new reference to the library the type came from in `_lib`.
if _lib:
core.BNFreeTypeLibrary(_lib)
if handle is None:
return None
return _types.Type.create(handle, platform=self.platform)
Expand Down Expand Up @@ -9255,15 +9256,16 @@ def import_library_object(self, name: str, lib: Optional[typelibrary.TypeLibrary
:rtype: Type
"""
_name = _types.QualifiedName(name)
_lib = ctypes.POINTER(ctypes.POINTER(core.BNTypeLibrary))()
_lib = ctypes.POINTER(core.BNTypeLibrary)()
if lib is not None:
_lib.contents = lib.handle
else:
_lib.contents = ctypes.POINTER(core.BNTypeLibrary)()
_lib = ctypes.cast(lib.handle, ctypes.POINTER(core.BNTypeLibrary))

handle = core.BNBinaryViewImportTypeLibraryObject(
self.handle, _lib, _name._to_core_struct()
self.handle, ctypes.byref(_lib), _name._to_core_struct()
)
# Core stores a new reference to the library the object came from in `_lib`.
if _lib:
core.BNFreeTypeLibrary(_lib)
if handle is None:
return None
return _types.Type.create(handle, platform=self.platform)
Expand Down
8 changes: 8 additions & 0 deletions rust/src/binary_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2804,6 +2804,10 @@ impl BinaryView {
let result =
unsafe { BNBinaryViewImportTypeLibraryType(self.handle, &mut lib_ref, &mut raw_name) };
QualifiedName::free_raw(raw_name);
// Core stores a new reference to the library the type came from in `lib_ref`.
if let Some(lib_ref) = NonNull::new(lib_ref) {
drop(unsafe { TypeLibrary::ref_from_raw(lib_ref) });
}
(!result.is_null()).then(|| unsafe { Type::ref_from_raw(result) })
}

Expand Down Expand Up @@ -2831,6 +2835,10 @@ impl BinaryView {
BNBinaryViewImportTypeLibraryObject(self.handle, &mut lib_ref, &mut raw_name)
};
QualifiedName::free_raw(raw_name);
// Core stores a new reference to the library the object came from in `lib_ref`.
if let Some(lib_ref) = NonNull::new(lib_ref) {
drop(unsafe { TypeLibrary::ref_from_raw(lib_ref) });
}
(!result.is_null()).then(|| unsafe { Type::ref_from_raw(result) })
}

Expand Down
Loading