Rust: don't leak fd on load_trusted_setup_file() error (#402)

This commit is contained in:
George Kadianakis 2024-03-04 16:50:27 +02:00 committed by GitHub
parent 2ab0c219fc
commit 8758b27792
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 3 deletions

View File

@ -193,6 +193,8 @@ impl KZGSettings {
let mut kzg_settings = MaybeUninit::<KZGSettings>::uninit();
let result = unsafe {
let res = load_trusted_setup_file(kzg_settings.as_mut_ptr(), file_ptr);
let _unchecked_close_result = libc::fclose(file_ptr);
if let C_KZG_RET::C_KZG_OK = res {
Ok(kzg_settings.assume_init())
} else {
@ -202,9 +204,6 @@ impl KZGSettings {
}
};
// We don't really care if this fails.
let _unchecked_close_result = unsafe { libc::fclose(file_ptr) };
result
}
}