Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leaks on ClipboardUtil::clipboard_text() and filesystem::base_path() #751

Merged
merged 1 commit into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/sdl2/clipboard.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::ffi::{CString, CStr};
use std::os::raw::c_void;
use libc::c_char;
use get_error;

Expand Down Expand Up @@ -48,7 +49,9 @@ impl ClipboardUtil {
if buf.is_null() {
Err(get_error())
} else {
Ok(CStr::from_ptr(buf as *const _).to_str().unwrap().to_owned())
let s = CStr::from_ptr(buf as *const _).to_str().unwrap().to_owned();
sys::SDL_free(buf as *mut c_void);
Ok(s)
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/sdl2/filesystem.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::error;
use std::ffi::{CStr, CString, NulError};
use std::fmt;
use std::os::raw::c_void;
use get_error;
use libc::c_char;

Expand All @@ -9,7 +10,9 @@ use sys;
pub fn base_path() -> Result<String, String> {
let result = unsafe {
let buf = sys::SDL_GetBasePath();
CStr::from_ptr(buf as *const _).to_str().unwrap().to_owned()
let s = CStr::from_ptr(buf as *const _).to_str().unwrap().to_owned();
sys::SDL_free(buf as *mut c_void);
s
};

if result.is_empty() {
Expand Down