From ed61660e26e97cb4659ef600ed2fad1162711f50 Mon Sep 17 00:00:00 2001 From: Thomas B <9094255+Ten0@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:24:51 +0200 Subject: [PATCH] fix memleak in connect_to_ceph fail (#107) --- src/ceph.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ceph.rs b/src/ceph.rs index ddc124d..77346a1 100644 --- a/src/ceph.rs +++ b/src/ceph.rs @@ -395,6 +395,13 @@ pub fn connect_to_ceph(user_id: &str, config_file: &str) -> RadosResult { if ret_code < 0 { return Err(ret_code.into()); } + // Instantiate Rados struct to call shutdown on drop. + // Doc specifies that it's not necessary to call rados_shutdown if + // rados_connect hasn't run, but that seems incorrect. + let rados = Rados { + rados: cluster_handle, + phantom: PhantomData, + }; let ret_code = rados_conf_read_file(cluster_handle, conf_file.as_ptr()); if ret_code < 0 { return Err(ret_code.into()); @@ -403,10 +410,7 @@ pub fn connect_to_ceph(user_id: &str, config_file: &str) -> RadosResult { if ret_code < 0 { return Err(ret_code.into()); } - Ok(Rados { - rados: cluster_handle, - phantom: PhantomData, - }) + Ok(rados) } }