python: do not pass NULL to ffi.gc if the context can't be created

This commit is contained in:
link2xt
2022-12-06 22:53:05 +00:00
committed by holger krekel
parent f11fceb63a
commit 35cd81a75f
2 changed files with 6 additions and 4 deletions

View File

@@ -82,12 +82,13 @@ class Account(object):
if hasattr(db_path, "encode"):
db_path = db_path.encode("utf8")
self._dc_context = ffi.gc(
lib.dc_context_new_closed(db_path) if closed else lib.dc_context_new(ffi.NULL, db_path, ffi.NULL),
lib.dc_context_unref,
)
ptr = lib.dc_context_new_closed(db_path) if closed else lib.dc_context_new(ffi.NULL, db_path, ffi.NULL)
if self._dc_context == ffi.NULL:
raise ValueError("Could not dc_context_new: {} {}".format(os_name, db_path))
self._dc_context = ffi.gc(
ptr,
lib.dc_context_unref,
)
self._shutdown_event = Event()
self._event_thread = EventThread(self)