Fix memory leaks (#28)

This commit is contained in:
daa 2017-12-03 19:45:38 +03:00
parent 2565b1e0fe
commit 778884ea96
3 changed files with 11 additions and 3 deletions

View File

@ -23,7 +23,7 @@ pub trait AttrIteratorFactory {
impl AttrIteratorFactory for pango::AttrList {
fn get_iterator(&self) -> AttrIterator {
unsafe {
from_glib_none(pango_sys::pango_attr_list_get_iterator(
from_glib_full(pango_sys::pango_attr_list_get_iterator(
self.to_glib_none().0,
))
}

View File

@ -23,7 +23,7 @@ impl Item {
#[cfg(test)]
pub fn new() -> Self {
unsafe {
from_glib_none(pango_sys::pango_item_new())
from_glib_full(pango_sys::pango_item_new())
}
}

View File

@ -10,6 +10,7 @@ use std::ptr;
use pango;
use pango_sys;
use glib_ffi;
use glib::translate::*;
@ -22,7 +23,8 @@ pub fn pango_itemize(
cached_iter: Option<&mut AttrIterator>,
) -> Vec<Item> {
unsafe {
FromGlibPtrContainer::from_glib_container(pango_sys::pango_itemize(
//FromGlibPtrContainer::from_glib_full(pango_sys::pango_itemize(
from_glib_full_as_vec(pango_sys::pango_itemize(
context.to_glib_none().0,
text.as_ptr() as *const i8,
start_index as i32,
@ -33,6 +35,12 @@ pub fn pango_itemize(
}
}
unsafe fn from_glib_full_as_vec(ptr: *mut glib_ffi::GList) -> Vec<Item> {
let num = glib_ffi::g_list_length(ptr) as usize;
FromGlibContainer::from_glib_full_num(ptr, num)
}
pub fn pango_shape(
text: &str,
offset: usize,