Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#[cfg(target_os = "ios")]
use crate::native::ios;

#[cfg(target_os = "android")]
use libc;

#[derive(Debug)]
pub enum Error {
IOError(std::io::Error),
Expand Down Expand Up @@ -64,6 +67,7 @@ fn load_file_android<F: Fn(Response)>(path: &str, on_loaded: F) {
let slice =
unsafe { std::slice::from_raw_parts(data.content, data.content_length as _) };
let response = slice.iter().map(|c| *c as _).collect::<Vec<_>>();
unsafe { libc::free(data.content as *mut std::ffi::c_void); };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the same problem here, isn't response a slice into data.content?

Ok(response)
} else {
Err(Error::AndroidAssetLoadingError)
Expand Down
4 changes: 3 additions & 1 deletion src/native/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,14 @@ pub(crate) unsafe fn load_asset(filepath: *const ::core::ffi::c_char, out: *mut
return;
}
let length = ndk_sys::AAsset_getLength64(asset);
// TODO: memory leak right here! this buffer would never freed
let buffer = libc::malloc(length as _);
if ndk_sys::AAsset_read(asset, buffer, length as _) > 0 {
ndk_sys::AAsset_close(asset);

(*out).content_length = length as _;
(*out).content = buffer as _;
} else {
libc::free(buffer);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it a use after free situation? buffer is being returned and than freed right away?

ndk_sys::AAsset_close(asset);
}
}
3 changes: 1 addition & 2 deletions src/native/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
if unsafe { GetClientRect(self.wnd, &mut rect as *mut _ as _) } != 0 {
let mut new_rect = rect;
new_rect.right = new_rect.right - new_rect.left + new_x as i32;
new_rect.bottom = new_rect.bottom - new_rect.top + new_y as i32;

Check warning on line 253 in src/native/windows.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

value assigned to `new_rect` is never read

Check warning on line 253 in src/native/windows.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

value assigned to `new_rect` is never read
unsafe {
SetWindowPos(
self.wnd,
Expand Down Expand Up @@ -608,8 +608,7 @@
let char_count = actual_len as usize / 2;
let mods = key_mods();
// Send chars in order
for i in 0..char_count {
let chr = buffer[i];
for &chr in &buffer[..char_count] {
if let Some(c) = char::from_u32(chr as u32) {
event_handler.char_event(c, mods, false);
}
Expand Down
Loading