Skip to content

Commit fb96296

Browse files
authored
Merge pull request #219 from mulimoen/bugfix/class_leak
Use H5Pisa_class to circumvent bug
2 parents d36d5b6 + 6b167cd commit fb96296

File tree

7 files changed

+55
-22
lines changed

7 files changed

+55
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
with feature `have-parallel` instead of `have-direct`.
2121
- Fixed a missing symbol when building `hdf5-src` with `libz-sys`.
2222
- Fixed a bug where errors were only silenced on the main thread.
23+
- Fixed a memory leak when opening datasets.
2324

2425
## 0.8.1
2526

src/hl/plist.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::ptr::{self, addr_of_mut};
55
use std::str::FromStr;
66

77
use hdf5_sys::h5p::{
8-
H5Pcopy, H5Pequal, H5Pexist, H5Pget_class, H5Pget_class_name, H5Pget_nprops, H5Piterate,
9-
H5Pset_vlen_mem_manager,
8+
H5Pcopy, H5Pequal, H5Pexist, H5Pget_class, H5Pget_class_name, H5Pget_nprops, H5Pisa_class,
9+
H5Piterate, H5Pset_vlen_mem_manager,
1010
};
1111

1212
use crate::internal_prelude::*;
@@ -208,6 +208,33 @@ impl PropertyList {
208208
PropertyListClass::from_str(&name)
209209
})
210210
}
211+
212+
pub fn is_class(&self, class: PropertyListClass) -> bool {
213+
use crate::globals::*;
214+
h5lock!({
215+
let class = match class {
216+
PropertyListClass::FileCreate => *H5P_FILE_CREATE,
217+
PropertyListClass::AttributeCreate => *H5P_ATTRIBUTE_CREATE,
218+
PropertyListClass::DatasetAccess => *H5P_DATASET_ACCESS,
219+
PropertyListClass::DatasetCreate => *H5P_DATASET_CREATE,
220+
PropertyListClass::DataTransfer => *H5P_DATASET_XFER,
221+
PropertyListClass::DatatypeAccess => *H5P_DATATYPE_ACCESS,
222+
PropertyListClass::DatatypeCreate => *H5P_DATATYPE_CREATE,
223+
PropertyListClass::FileAccess => *H5P_FILE_ACCESS,
224+
PropertyListClass::FileMount => *H5P_FILE_MOUNT,
225+
PropertyListClass::GroupAccess => *H5P_GROUP_ACCESS,
226+
PropertyListClass::GroupCreate => *H5P_GROUP_CREATE,
227+
PropertyListClass::LinkAccess => *H5P_LINK_ACCESS,
228+
PropertyListClass::LinkCreate => *H5P_LINK_CREATE,
229+
PropertyListClass::ObjectCopy => *H5P_OBJECT_COPY,
230+
PropertyListClass::ObjectCreate => *H5P_OBJECT_CREATE,
231+
PropertyListClass::StringCreate => *H5P_STRING_CREATE,
232+
};
233+
let tri = H5Pisa_class(self.id(), class);
234+
235+
tri == 1
236+
})
237+
}
211238
}
212239

213240
/// Set the memory manager for variable length items to

src/hl/plist/dataset_access.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ impl ObjectClass for DatasetAccess {
4343
}
4444

4545
fn validate(&self) -> Result<()> {
46-
let class = self.class()?;
47-
if class != PropertyListClass::DatasetAccess {
48-
fail!("expected dataset access property list, got {:?}", class);
49-
}
46+
ensure!(
47+
self.is_class(PropertyListClass::DatasetAccess),
48+
"expected dataset access property list, got {:?}",
49+
self.class()
50+
);
5051
Ok(())
5152
}
5253
}

src/hl/plist/dataset_create.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ impl ObjectClass for DatasetCreate {
5555
}
5656

5757
fn validate(&self) -> Result<()> {
58-
let class = self.class()?;
59-
if class != PropertyListClass::DatasetCreate {
60-
fail!("expected dataset creation property list, got {:?}", class);
61-
}
58+
ensure!(
59+
self.is_class(PropertyListClass::DatasetCreate),
60+
"expected dataset creation property list, got {:?}",
61+
self.class()
62+
);
6263
Ok(())
6364
}
6465
}

src/hl/plist/file_access.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ impl ObjectClass for FileAccess {
9999
}
100100

101101
fn validate(&self) -> Result<()> {
102-
let class = self.class()?;
103-
if class != PropertyListClass::FileAccess {
104-
fail!("expected file access property list, got {:?}", class);
105-
}
102+
ensure!(
103+
self.is_class(PropertyListClass::FileAccess),
104+
"expected file access property list, got {:?}",
105+
self.class()
106+
);
106107
Ok(())
107108
}
108109
}

src/hl/plist/file_create.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ impl ObjectClass for FileCreate {
4747
}
4848

4949
fn validate(&self) -> Result<()> {
50-
let class = self.class()?;
51-
if class != PropertyListClass::FileCreate {
52-
fail!("expected file create property list, got {:?}", class);
53-
}
50+
ensure!(
51+
self.is_class(PropertyListClass::FileCreate),
52+
"expected file create property list, got {:?}",
53+
self.class()
54+
);
5455
Ok(())
5556
}
5657
}

src/hl/plist/link_create.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ impl ObjectClass for LinkCreate {
2929
}
3030

3131
fn validate(&self) -> Result<()> {
32-
let class = self.class()?;
33-
if class != PropertyListClass::LinkCreate {
34-
fail!("expected link create property list, got {:?}", class);
35-
}
32+
ensure!(
33+
self.is_class(PropertyListClass::LinkCreate),
34+
"expected link create property list, got {:?}",
35+
self.class()
36+
);
3637
Ok(())
3738
}
3839
}

0 commit comments

Comments
 (0)