File tree 1 file changed +21
-2
lines changed
1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 1
1
use std:: {
2
2
collections:: { HashMap , HashSet } ,
3
3
ffi:: { CString , OsString } ,
4
- fs:: canonicalize,
4
+ fs:: { canonicalize, File } ,
5
5
io:: ErrorKind ,
6
- os:: { fd:: RawFd , unix:: ffi:: OsStrExt } ,
6
+ os:: {
7
+ fd:: { FromRawFd , RawFd } ,
8
+ unix:: ffi:: OsStrExt ,
9
+ } ,
7
10
path:: { absolute, PathBuf } ,
8
11
} ;
9
12
@@ -125,6 +128,16 @@ impl UhyveFileMap {
125
128
ret
126
129
}
127
130
131
+ // Drops all file descriptors present in fdmap and unlinkedfd.
132
+ pub fn drop_all_fds ( & self ) {
133
+ for ( fd, _) in & self . fdmap {
134
+ unsafe { File :: from_raw_fd ( * fd) } ;
135
+ }
136
+ for fd in self . unlinkedfd . iter ( ) {
137
+ unsafe { File :: from_raw_fd ( * fd) } ;
138
+ }
139
+ }
140
+
128
141
/// Checks whether the fd is mapped to a guest path or belongs
129
142
/// to an unlinked file.
130
143
///
@@ -201,6 +214,12 @@ impl UhyveFileMap {
201
214
}
202
215
}
203
216
217
+ impl Drop for UhyveFileMap {
218
+ fn drop ( & mut self ) {
219
+ self . drop_all_fds ( ) ;
220
+ }
221
+ }
222
+
204
223
#[ cfg( test) ]
205
224
mod tests {
206
225
use super :: * ;
You can’t perform that action at this time.
0 commit comments