Skip to content

Commit 4c4df4a

Browse files
committed
do not partially deallocate the state
1 parent 7b862ca commit 4c4df4a

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

zlib-rs/src/inflate/infback.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,17 @@ pub fn back_init(stream: &mut z_stream, config: InflateConfig, window: Window) -
7474
stream.state = state_allocation.cast::<internal_state>();
7575

7676
// SAFETY: we've correctly initialized the stream to be an InflateStream
77-
let ret = if let Some(stream) = unsafe { InflateStream::from_stream_mut(stream) } {
78-
stream.state.allocation_start = allocation_start.as_ptr();
79-
stream.state.total_allocation_size = allocs.total_size;
80-
81-
stream.state.wbits = config.window_bits as u8;
82-
stream.state.flags.update(Flags::SANE, true);
83-
ReturnCode::Ok
84-
} else {
85-
ReturnCode::StreamError
77+
let Some(stream) = (unsafe { InflateStream::from_stream_mut(stream) }) else {
78+
return ReturnCode::StreamError;
8679
};
8780

88-
if ret != ReturnCode::Ok {
89-
let ptr = stream.state;
90-
stream.state = core::ptr::null_mut();
91-
// SAFETY: we assume deallocation does not cause UB
92-
unsafe { alloc.deallocate(ptr, 1) };
93-
}
81+
stream.state.allocation_start = allocation_start.as_ptr();
82+
stream.state.total_allocation_size = allocs.total_size;
9483

95-
ret
84+
stream.state.wbits = config.window_bits as u8;
85+
stream.state.flags.update(Flags::SANE, true);
86+
87+
ReturnCode::Ok
9688
}
9789

9890
pub unsafe fn back(

0 commit comments

Comments
 (0)