summaryrefslogtreecommitdiff
path: root/rust/examples
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2024-06-27 17:01:37 -0400
committerGlenn Smith <glenn@vector35.com>2024-06-27 17:01:37 -0400
commit7d6dd01919b3e5bac028bdcecb36f9f120ff197d (patch)
treee349dcdbf2b3ea25a0e7fe15f16c88516cbd998c /rust/examples
parentafa9a63059b47544a410b4fbd651041dc798e267 (diff)
Fix debuginfod downloads leaking a BinaryView
It wasn't closing the downloaded FileMetadata object
Diffstat (limited to 'rust/examples')
-rw-r--r--rust/examples/dwarf/dwarf_import/src/lib.rs43
1 files changed, 21 insertions, 22 deletions
diff --git a/rust/examples/dwarf/dwarf_import/src/lib.rs b/rust/examples/dwarf/dwarf_import/src/lib.rs
index 63f5142f..374baa37 100644
--- a/rust/examples/dwarf/dwarf_import/src/lib.rs
+++ b/rust/examples/dwarf/dwarf_import/src/lib.rs
@@ -382,43 +382,42 @@ impl CustomDebugInfoParser for DWARFParser {
debug_file: &BinaryView,
progress: Box<dyn Fn(usize, usize) -> Result<(), ()>>,
) -> bool {
- let external_file = if !dwarfreader::is_valid(bv) {
+ let (external_file, close_external) = if !dwarfreader::is_valid(bv) {
if dwarfreader::has_build_id_section(bv) {
if let Ok(Some(debug_view)) = helpers::load_debug_info_for_build_id(bv) {
- Some(debug_view)
- }
- else {
+ (Some(debug_view), false)
+ } else {
if dwarfreader::can_use_debuginfod(bv) {
if let Ok(debug_view) = helpers::download_debug_info(bv) {
- Some(debug_view)
+ (Some(debug_view), true)
} else {
- None
+ (None, false)
}
- }
- else {
- None
+ } else {
+ (None, false)
}
}
+ } else {
+ (None, false)
}
- else {
- None
- }
- }
- else {
- None
+ } else {
+ (None, false)
};
- match parse_dwarf(bv, external_file.as_deref().unwrap_or(debug_file), progress) {
+ let result = match parse_dwarf(bv, external_file.as_deref().unwrap_or(debug_file), progress)
+ {
Ok(mut builder) => {
- builder
- .post_process(bv, debug_info)
- .commit_info(debug_info);
+ builder.post_process(bv, debug_info).commit_info(debug_info);
true
- },
- Err(_) => {
- false
}
+ Err(_) => false,
+ };
+
+ if let (Some(ext), true) = (external_file, close_external) {
+ ext.file().close();
}
+
+ result
}
}