From 8199dd3294d4fe882c5fdabc099e051ea5b647cf Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Fri, 17 Feb 2023 10:10:11 +0100 Subject: [PATCH] If pgp_release is passed a NULL pointer, do nothing - In C, it is usually okay to call a destructor, like `free`, with a `NULL` pointer: the function just does nothing. Implement the same semantics for `pgp_release`. - See #26. --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index dd0d218..6e8b4b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -314,7 +314,12 @@ API violation: per_user_directory not UTF-8 encoded ({:?}: {})", // void pgp_release(PEP_SESSION session, bool out_last) ffi!(fn pgp_release(session: *mut Session, _out_last: bool) -> Result<()> { - Session::as_mut(session)?.deinit(); + // In C, it is usually okay to call a destructor, like `free`, + // with a `NULL` pointer: the function just does nothing. + // Implement the same semantics. + if ! session.is_null() { + Session::as_mut(session)?.deinit(); + } Ok(()) }); -- GitLab