diff --git a/src/CaosDB.jl b/src/CaosDB.jl index 7daec21cf08dda691dfccf981f7983416a830362..1f451f770488beae53e811c843c116d197ae34ef 100644 --- a/src/CaosDB.jl +++ b/src/CaosDB.jl @@ -81,13 +81,13 @@ authenticator object from a configuration. mutable struct _Authenticator wrapped_authenticator::Ptr{Cvoid} - function _Authenticator() + function _Authenticator(managed_by_julia::Bool=false) auth = new() - # force this to point to C_NULL after initialization - auth.wrapped_authenticator = C_NULL - function f(t) - if t.wrapped_authenticator != C_NULL - # Only if pointer was filled after real initialization + if managed_by_julia + # Only append a finalizer for this if the object is + # actually managed by Julia and not created and destroyed + # internally by libcaosdb. + function f(t) ccall( (:caosdb_authentication_delete_authenticator, "libccaosdb"), Cint, @@ -95,8 +95,9 @@ mutable struct _Authenticator Ref{_Authenticator}(t), ) end + finalizer(f, auth) end - finalizer(f, auth) + return auth end end @@ -115,7 +116,7 @@ function create_plain_password_authenticator( password::AbstractString, ) - auth = Ref{_Authenticator}(_Authenticator()) + auth = Ref{_Authenticator}(_Authenticator(true)) err_code = ccall( (:caosdb_authentication_create_plain_password_authenticator, "libccaosdb"), diff --git a/src/Connection.jl b/src/Connection.jl index 339df952cfc0872750dbe901fef53057bff32a3e..6b267ac240ca7909be540d1ad2bc5713cec59102 100644 --- a/src/Connection.jl +++ b/src/Connection.jl @@ -96,6 +96,9 @@ mutable struct _Configuration function _Configuration(managed_by_julia::Bool=false) config = new() if managed_by_julia + # Only append a finalizer for this if the object is + # actually managed by Julia and not created and destroyed + # internally by libcaosdb. function f(t) ccall( (:caosdb_connection_delete_connection_configuration, "libccaosdb"), @@ -274,7 +277,7 @@ to. """ function get_version_info(con::Ref{_Connection}) - info = Ref{CaosDB.Info._VersionInfo}(CaosDB.Info._VersionInfo(true)) + info = Ref{CaosDB.Info._VersionInfo}(CaosDB.Info._VersionInfo()) err_code = ccall( (:caosdb_connection_get_version_info, "libccaosdb"),