Skip to content

Commit

Permalink
Release owned pointer when dropping PopplerDocument and PopplerPage (#12
Browse files Browse the repository at this point in the history
)

Co-authored-by: Denys Vitali <[email protected]>
  • Loading branch information
enawder and denysvitali authored Aug 5, 2024
1 parent 42b2806 commit ed60d98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ render = ["dep:cairo-rs"]
[dependencies]
cairo-rs = { version = "0.18.5", features = ["png", "pdf"], optional = true }
glib = "0.18.5"
gobject-sys = "0.15"
17 changes: 16 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ impl PopplerDocument {
}
}

impl Drop for PopplerDocument {
fn drop(&mut self) {
unsafe {
gobject_sys::g_object_unref(self.0 as *mut gobject_sys::GObject);
}
}
}

impl PopplerPage {
pub fn get_size(&self) -> (f64, f64) {
let mut width: f64 = 0.0;
Expand Down Expand Up @@ -182,6 +190,14 @@ impl<'a> Iterator for PagesIter<'a> {
}
}

impl Drop for PopplerPage {
fn drop(&mut self) {
unsafe {
gobject_sys::g_object_unref(self.0 as *mut gobject_sys::GObject);
}
}
}

#[cfg(test)]
mod tests {
use crate::PopplerDocument;
Expand Down Expand Up @@ -226,7 +242,6 @@ mod tests {
ctx.show_page().unwrap();
})(&ctx);
}
// g_object_unref (page);
//surface.write_to_png("file.png");
#[cfg(feature = "render")]
surface.finish();
Expand Down

0 comments on commit ed60d98

Please sign in to comment.