Skip to content
Merged
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
37 changes: 26 additions & 11 deletions src/c2pa/c2pa.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,12 @@ def __init__(self):
super().__init__()

ptr = _lib.c2pa_settings_new()
_check_ffi_operation_result(ptr, "Failed to create Settings")
try:
_check_ffi_operation_result(ptr, "Failed to create Settings")
except Exception:
if ptr:
ManagedResource._free_native_ptr(ptr)
raise

self._handle = ptr
self._lifecycle_state = LifecycleState.ACTIVE
Expand Down Expand Up @@ -2403,11 +2408,16 @@ def _init_from_context(self, context, format_or_path,
reader_ptr = _lib.c2pa_reader_from_context(
context.execution_context,
)
_check_ffi_operation_result(reader_ptr,
Reader._ERROR_MESSAGES[
'reader_error'
].format("Unknown error")
)
try:
_check_ffi_operation_result(reader_ptr,
Reader._ERROR_MESSAGES[
'reader_error'
].format("Unknown error")
)
except Exception:
if reader_ptr:
ManagedResource._free_native_ptr(reader_ptr)
raise

if manifest_data is not None:
if not isinstance(manifest_data, bytes):
Expand Down Expand Up @@ -3176,11 +3186,16 @@ def _init_from_context(self, context, json_str):
builder_ptr = _lib.c2pa_builder_from_context(
context.execution_context,
)
_check_ffi_operation_result(builder_ptr,
Builder._ERROR_MESSAGES[
'builder_error'
].format("Unknown error")
)
try:
_check_ffi_operation_result(builder_ptr,
Builder._ERROR_MESSAGES[
'builder_error'
].format("Unknown error")
)
except Exception:
if builder_ptr:
ManagedResource._free_native_ptr(builder_ptr)
raise

# Consume-and-return: builder_ptr is consumed,
# new_ptr is the valid pointer going forward
Expand Down
Loading