Skip to content

Fix memory leak in Android asset loading and optimize Windows IME loop#598

Open
KrishGoya1 wants to merge 1 commit intonot-fl3:masterfrom
KrishGoya1:master
Open

Fix memory leak in Android asset loading and optimize Windows IME loop#598
KrishGoya1 wants to merge 1 commit intonot-fl3:masterfrom
KrishGoya1:master

Conversation

@KrishGoya1
Copy link

Summary :

  1. fixes memory leak in android asset loading
    -> in src/native/android.rs and src/fs.rs by freeing malloc buffers after loading assets to prevent memory leak crashes in Android apps

  2. Optimizes windows IME loop
    -> in src/native/windows.rs replaced range loop with idiomatic iteration.

Testing :
code compiles successfully with cargo check

- Fix memory leak in Android asset loading by properly freeing malloc'd buffers
- Optimize needless range loop in Windows IME composition string handling
- Reduce Clippy warnings from 4 to 3
(*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?

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants