Free on error. Use pub(crate). Minor fixes.

This commit is contained in:
Bo Du 2018-04-05 10:46:13 -04:00 committed by Sebastian Dröge
parent 3ecd67ee46
commit 05fec4d927
9 changed files with 24 additions and 14 deletions

View file

@ -21,12 +21,13 @@ impl MIKEYPayload {
pub fn kemac_add_sub(&mut self, newpay: MIKEYPayload) -> bool {
unsafe {
from_glib(ffi::gst_mikey_payload_kemac_add_sub(self.to_glib_none_mut().0, newpay.to_glib_full()))
}
let ret = from_glib(ffi::gst_mikey_payload_kemac_add_sub(self.to_glib_none_mut().0, newpay.to_glib_full()));
mem::forget(newpay);
ret
}
}
pub fn kemac_get_sub(&self, idx: u32) -> Option<MIKEYPayload> {
pub fn kemac_get_sub(&self, idx: u32) -> Option<&MIKEYPayload> {
unsafe {
&*(from_glib_none(ffi::gst_mikey_payload_kemac_get_sub(self.to_glib_none().0, idx)) as *mut MIKEYPayload)
}

View file

@ -15,7 +15,7 @@ use glib::translate::*;
use auto::SDPResult;
#[repr(C)]
pub struct SDPAttribute(pub ffi::GstSDPAttribute);
pub struct SDPAttribute(pub(crate) ffi::GstSDPAttribute);
impl SDPAttribute {
pub fn new(key: &str, value: &str) -> Result<Self, ()> {

View file

@ -15,7 +15,7 @@ use glib::translate::*;
use auto::SDPResult;
#[repr(C)]
pub struct SDPBandwidth(pub ffi::GstSDPBandwidth);
pub struct SDPBandwidth(pub(crate) ffi::GstSDPBandwidth);
impl SDPBandwidth {
pub fn new(bwtype: &str, bandwidth: u32) -> Result<Self, ()> {

View file

@ -15,7 +15,7 @@ use glib::translate::*;
use auto::SDPResult;
#[repr(C)]
pub struct SDPConnection(pub ffi::GstSDPConnection);
pub struct SDPConnection(pub(crate) ffi::GstSDPConnection);
impl SDPConnection {
pub fn new(nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Result<Self, ()> {

View file

@ -40,12 +40,15 @@ glib_wrapper! {
}
impl SDPMedia {
pub fn new() -> (SDPResult, SDPMedia) {
pub fn new() -> Result<Self, ()> {
assert_initialized_main_thread!();
unsafe {
let mut media = ptr::null_mut();
let ret = from_glib(ffi::gst_sdp_media_new(&mut media));
(ret, from_glib_full(media))
let result = from_glib(ffi::gst_sdp_media_new(&mut media));
match result {
SDPResult::Ok => Ok(from_glib_full(media)),
_ => Err(()),
}
}
}

View file

@ -672,7 +672,10 @@ impl SDPMessage {
let result = from_glib(ffi::gst_sdp_message_parse_buffer(data.to_glib_none().0, size, msg));
match result {
SDPResult::Ok => Ok(from_glib_full(msg)),
_ => Err(()),
_ => {
glib_ffi::g_free(msg as *mut _);
Err(())
},
}
}
}
@ -684,7 +687,10 @@ impl SDPMessage {
let result = from_glib(ffi::gst_sdp_message_parse_uri(uri.to_glib_none().0, msg));
match result {
SDPResult::Ok => Ok(from_glib_full(msg)),
_ => Err(()),
_ => {
glib_ffi::g_free(msg as *mut _);
Err(())
},
}
}
}

View file

@ -11,7 +11,7 @@ use std::ffi::CStr;
use ffi;
#[repr(C)]
pub struct SDPOrigin(pub ffi::GstSDPOrigin);
pub struct SDPOrigin(pub(crate) ffi::GstSDPOrigin);
impl SDPOrigin {
pub fn username(&self) -> &str {

View file

@ -16,7 +16,7 @@ use glib::translate::*;
use auto::SDPResult;
#[repr(C)]
pub struct SDPTime(pub ffi::GstSDPTime);
pub struct SDPTime(pub(crate) ffi::GstSDPTime);
impl SDPTime {
pub fn new(start: &str, stop: &str, repeat: &[&str]) -> Result<Self, ()> {

View file

@ -15,7 +15,7 @@ use glib::translate::*;
use auto::SDPResult;
#[repr(C)]
pub struct SDPZone(pub ffi::GstSDPZone);
pub struct SDPZone(pub(crate) ffi::GstSDPZone);
impl SDPZone {
pub fn new(time: &str, typed_time: &str) -> Result<Self, ()> {