Skip to content

Commit

Permalink
Fixed a memory leak
Browse files Browse the repository at this point in the history
Added unpack_end() when decompressor is dealloced.
  • Loading branch information
ifeherva committed Aug 8, 2017
1 parent 00a721e commit 978dcc0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "decrunch"
version = "0.1.0"
version = "0.1.1"
authors = ["Istvan Fehervari <gooksl@gmail.com>"]
description = "Decoder for crunch-compressed texture data."
license = "MIT"
Expand Down
5 changes: 5 additions & 0 deletions crunch/crn_decomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ void *crnd_unpack_begin(const void *pData, crnd::uint32 data_size)
return crnd::crnd_unpack_begin(pData, data_size);
}

bool crnd_unpack_end(crnd::crnd_unpack_context pContext)
{
return crnd::crnd_unpack_end(pContext);
}

bool crnd_unpack_level(
crnd::crnd_unpack_context pContext,
void **ppDst, crnd::uint32 dst_size_in_bytes, crnd::uint32 row_pitch_in_bytes,
Expand Down
8 changes: 8 additions & 0 deletions src/crunch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extern "C" {

fn crnd_unpack_begin(pData: *const uint8_t, data_size: uint32_t) -> *const c_void;

fn crnd_unpack_end(ctx: *const c_void) -> c_int;

fn crnd_unpack_level(
pContext: *const c_void,
ppDst: *const *const uint8_t,
Expand Down Expand Up @@ -95,3 +97,9 @@ pub fn unpack_level(
) > 0
}
}

pub fn unpack_end(ctx: *const c_void) {
unsafe {
crnd_unpack_end(ctx);
}
}
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,19 @@ impl<'a> CrunchedData<'a> {
&mut dst,
info.blocks_x * info.bytes_per_block,
level,
) {
)
{
return None;
}
Some(dst)
}
}

impl<'a> Drop for CrunchedData<'a> {
fn drop(&mut self) {
crunch::unpack_end(self.ctx);
}
}

#[cfg(test)]
mod tests;

0 comments on commit 978dcc0

Please sign in to comment.