Skip to content

Commit ed61660

Browse files
authored
fix memleak in connect_to_ceph fail (#107)
1 parent d049e23 commit ed61660

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/ceph.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ pub fn connect_to_ceph(user_id: &str, config_file: &str) -> RadosResult<Rados> {
395395
if ret_code < 0 {
396396
return Err(ret_code.into());
397397
}
398+
// Instantiate Rados struct to call shutdown on drop.
399+
// Doc specifies that it's not necessary to call rados_shutdown if
400+
// rados_connect hasn't run, but that seems incorrect.
401+
let rados = Rados {
402+
rados: cluster_handle,
403+
phantom: PhantomData,
404+
};
398405
let ret_code = rados_conf_read_file(cluster_handle, conf_file.as_ptr());
399406
if ret_code < 0 {
400407
return Err(ret_code.into());
@@ -403,10 +410,7 @@ pub fn connect_to_ceph(user_id: &str, config_file: &str) -> RadosResult<Rados> {
403410
if ret_code < 0 {
404411
return Err(ret_code.into());
405412
}
406-
Ok(Rados {
407-
rados: cluster_handle,
408-
phantom: PhantomData,
409-
})
413+
Ok(rados)
410414
}
411415
}
412416

0 commit comments

Comments
 (0)