@@ -37,6 +37,8 @@ pub struct FileDetails {
37
37
pub content : * mut u8 ,
38
38
/// Size of `content`
39
39
pub content_len : usize ,
40
+ /// Capacity of `content`. Only used by the allocator's `dealloc` algorithm.
41
+ pub content_cap : usize ,
40
42
/// Metadata of the file.
41
43
pub metadata : * mut FileMetadata ,
42
44
}
@@ -59,7 +61,7 @@ impl FileDetails {
59
61
60
62
let content = try!( reader. read ( start_position, size) ) ;
61
63
let content = content. to_base64 ( config:: get_base64_config ( ) ) ;
62
- let ( content, content_len) = helper:: string_to_c_utf8 ( content) ;
64
+ let ( content, content_len, content_cap ) = helper:: string_to_c_utf8 ( content) ;
63
65
64
66
let file_metadata_ptr = if include_metadata {
65
67
Box :: into_raw ( Box :: new ( try!( FileMetadata :: new ( file. get_metadata ( ) ) ) ) )
@@ -70,6 +72,7 @@ impl FileDetails {
70
72
Ok ( FileDetails {
71
73
content : content,
72
74
content_len : content_len,
75
+ content_cap : content_cap,
73
76
metadata : file_metadata_ptr,
74
77
} )
75
78
}
@@ -78,7 +81,9 @@ impl FileDetails {
78
81
// a proper impl Drop.
79
82
fn deallocate ( self ) {
80
83
unsafe {
81
- helper:: dealloc_c_utf8_alloced_from_rust ( self . content , self . content_len ) ;
84
+ helper:: dealloc_c_utf8_alloced_from_rust ( self . content ,
85
+ self . content_len ,
86
+ self . content_cap ) ;
82
87
}
83
88
84
89
if !self . metadata . is_null ( ) {
@@ -94,8 +99,10 @@ impl FileDetails {
94
99
pub struct FileMetadata {
95
100
pub name : * mut u8 ,
96
101
pub name_len : usize ,
102
+ pub name_cap : usize ,
97
103
pub user_metadata : * mut u8 ,
98
104
pub user_metadata_len : usize ,
105
+ pub user_metadata_cap : usize ,
99
106
pub size : i64 ,
100
107
pub creation_time_sec : i64 ,
101
108
pub creation_time_nsec : i64 ,
@@ -111,18 +118,22 @@ impl FileMetadata {
111
118
let created_time = file_metadata. get_created_time ( ) . to_timespec ( ) ;
112
119
let modified_time = file_metadata. get_modified_time ( ) . to_timespec ( ) ;
113
120
114
- let ( name, name_len) = helper:: string_to_c_utf8 ( file_metadata. get_name ( ) . to_string ( ) ) ;
121
+ let ( name, name_len, name_cap) = helper:: string_to_c_utf8 ( file_metadata. get_name ( )
122
+ . to_string ( ) ) ;
115
123
116
124
let user_metadata = file_metadata. get_user_metadata ( )
117
125
. to_base64 ( config:: get_base64_config ( ) ) ;
118
- let ( user_metadata, user_metadata_len) = helper:: string_to_c_utf8 ( user_metadata) ;
126
+ let ( user_metadata, user_metadata_len, user_metadata_cap) =
127
+ helper:: string_to_c_utf8 ( user_metadata) ;
119
128
120
129
Ok ( FileMetadata {
121
130
name : name,
122
131
name_len : name_len,
132
+ name_cap : name_cap,
123
133
size : file_metadata. get_size ( ) as i64 ,
124
134
user_metadata : user_metadata,
125
135
user_metadata_len : user_metadata_len,
136
+ user_metadata_cap : user_metadata_cap,
126
137
creation_time_sec : created_time. sec ,
127
138
creation_time_nsec : created_time. nsec as i64 ,
128
139
modification_time_sec : modified_time. sec ,
@@ -135,8 +146,10 @@ impl FileMetadata {
135
146
// a proper impl Drop.
136
147
pub fn deallocate ( & mut self ) {
137
148
unsafe {
138
- helper:: dealloc_c_utf8_alloced_from_rust ( self . name , self . name_len ) ;
139
- helper:: dealloc_c_utf8_alloced_from_rust ( self . user_metadata , self . user_metadata_len ) ;
149
+ helper:: dealloc_c_utf8_alloced_from_rust ( self . name , self . name_len , self . name_cap ) ;
150
+ helper:: dealloc_c_utf8_alloced_from_rust ( self . user_metadata ,
151
+ self . user_metadata_len ,
152
+ self . user_metadata_cap ) ;
140
153
}
141
154
}
142
155
}
0 commit comments