Skip to content

Commit

Permalink
Fix memory leak when dropping locale guard.
Browse files Browse the repository at this point in the history
  • Loading branch information
awused authored and otavio committed Jul 27, 2021
1 parent abb2b97 commit 5118320
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ffi/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) use inner::UTF8LocaleGuard;
mod inner {
pub(crate) struct UTF8LocaleGuard {
save: libc::locale_t,
utf8_locale: libc::locale_t,
}

impl UTF8LocaleGuard {
Expand All @@ -36,13 +37,16 @@ mod inner {

let save = unsafe { libc::uselocale(utf8_locale) };

Self { save }
Self { save, utf8_locale }
}
}

impl Drop for UTF8LocaleGuard {
fn drop(&mut self) {
unsafe { libc::uselocale(self.save) };
unsafe {
libc::uselocale(self.save);
libc::freelocale(self.utf8_locale);
};
}
}
}
Expand Down

0 comments on commit 5118320

Please sign in to comment.