Skip to content

Commit c474dfc

Browse files
committed
Enable leak detector & fix few memleaks
1 parent eb4a0ba commit c474dfc

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: dtolnay/rust-toolchain@nightly
1414
- name: Run tests
1515
run: |
16-
RUSTFLAGS="-D warnings -Z sanitizer=address" ASAN_OPTIONS=detect_leaks=0 cargo test
16+
RUSTFLAGS="-D warnings -Z sanitizer=address" ASAN_OPTIONS=detect_leaks=1 cargo test
1717
1818
rustfmt:
1919
name: Rustfmt

src/lapi.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ pub unsafe fn lua_istable(L: *mut lua_State, n: c_int) -> bool {
6767
}
6868

6969
pub unsafe fn lua_pushliteral(L: *mut lua_State, s: &str) {
70-
let cstr = CString::new(s).unwrap().into_raw();
71-
lua_pushstring(L, cstr);
70+
// TODO: Redesign
71+
let s = CString::new(s).expect("valid literal");
72+
lua_pushstring(L, s.as_ptr());
7273
}
7374

7475
pub const fn lua_upvalueindex(i: c_int) -> c_int {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
pub(crate) mod macros;
1111

1212
#[macro_use]
13-
pub(crate) mod lstate;
13+
pub mod lstate; // TODO: update visibility
1414
#[macro_use]
1515
pub(crate) mod lobject;
1616
#[macro_use]

src/lmathlib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ unsafe extern "C" fn lua_numbertointeger(n: lua_Number, p: *mut lua_Integer) ->
5050
return false;
5151
}
5252

53-
// FIXME static
5453
#[no_mangle]
5554
unsafe extern "C" fn pushnumint(L: *mut lua_State, d: lua_Number) {
56-
let n: *mut lua_Integer = Box::into_raw(Box::new(0));
57-
if lua_numbertointeger(d, n) {
58-
lua_pushinteger(L, *n);
55+
let mut n: lua_Integer = 0;
56+
if lua_numbertointeger(d, &mut n) {
57+
lua_pushinteger(L, n);
5958
} else {
6059
lua_pushnumber(L, d);
6160
};

tests/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::ptr;
44
use rustmoon::cstr;
55
use rustmoon::lapi::lua_call;
66
use rustmoon::lauxlib::{luaL_loadfilex, luaL_loadstring, luaL_newstate};
7+
use rustmoon::lstate::lua_close;
78
use rustmoon::lualib::luaL_openlibs;
89
use rustmoon::types::LUA_OK;
910

@@ -27,6 +28,8 @@ fn test_all() {
2728
panic!("Failed to load `all.lua`");
2829
}
2930
lua_call(state, 0, 0);
31+
32+
lua_close(state);
3033
})
3134
.unwrap()
3235
.join()

0 commit comments

Comments
 (0)