diff --git a/src/CaosDB.jl b/src/CaosDB.jl index f3155f11bffad7b34fdd7ef3d2ed1ee1e947360e..51a437f81012cb5cd1c987f9087c106a950daa65 100644 --- a/src/CaosDB.jl +++ b/src/CaosDB.jl @@ -75,7 +75,23 @@ Struct containing a pointer to the wrapped cpp authenticator class. mutable struct Authenticator wrapped_authenticator::Ptr{Cvoid} - Authenticator() = new() + function Authenticator() + 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 + ccall( + (:caosdb_authentication_delete_authenticator, "libccaosdb"), + Cint, + (Ref{Authenticator},), + Ref{Authenticator}(t), + ) + end + end + finalizer(f, auth) + end end function create_plain_password_authenticator( @@ -116,7 +132,21 @@ Struct containing the actual connection to a CaosDB server. mutable struct CaosDBConnection wrapped_connection::Ptr{Cvoid} - CaosDBConnection() = new() + function CaosDBConnection() + conn = new() + conn.wrapped_connection = C_NULL + function f(t) + if t.wrapped_connection != C_NULL + ccall( + (:caosdb_connection_delete_connection, "libccaosdb"), + Cint, + (Ref{CaosDBConnection},), + Ref{CaosDBConnection}(t), + ) + end + end + finalizer(f, conn) + end end """ @@ -126,7 +156,21 @@ certificate provider. mutable struct CertificateProvider wrapped_certificate_provider::Ptr{Cvoid} - CertificateProvider() = new() + function CertificateProvider() + prov = new() + prov.wrapped_certificate_provider = C_NULL + function f(t) + if t.wrapped_certificate_provider != C_NULL + ccall( + (:caosdb_connection_delete_certificate_provider, "libccaosdb"), + Cint, + (Ref{CertificateProvider},), + Ref{CertificateProvider}(t), + ) + end + end + finalizer(f, prov) + end end """ @@ -136,7 +180,21 @@ connection configuration. mutable struct Configuration wrapped_connection_configuration::Ptr{Cvoid} - Configuration() = new() + function Configuration() + config = new() + config.wrapped_connection_configuration = C_NULL + function f(t) + if t.wrapped_connection_configuration != C_NULL + ccall( + (:caosdb_connection_delete_connection_configuration, "libcaosdb"), + Cint, + (Ref{Configuration},), + Ref{Configuration}(t), + ) + end + end + finalizer(f, config) + end end """