Commit 4f097cf0 authored by dnc40085's avatar dnc40085
Browse files

Fixed memory leak in tmr.alarm()

parent 608d5f6b
...@@ -11,12 +11,19 @@ ...@@ -11,12 +11,19 @@
static os_timer_t alarm_timer[NUM_TMR]; static os_timer_t alarm_timer[NUM_TMR];
static int alarm_timer_cb_ref[NUM_TMR] = {LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF}; static int alarm_timer_cb_ref[NUM_TMR] = {LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF,LUA_NOREF};
static bool alarm_timer_repeat[NUM_TMR]= {0,0,0,0,0,0,0};
void alarm_timer_common(lua_State* L, unsigned id){ void alarm_timer_common(lua_State* L, unsigned id){
if(alarm_timer_cb_ref[id] == LUA_NOREF) if(alarm_timer_cb_ref[id] == LUA_NOREF)
return; return;
lua_rawgeti(L, LUA_REGISTRYINDEX, alarm_timer_cb_ref[id]); lua_rawgeti(L, LUA_REGISTRYINDEX, alarm_timer_cb_ref[id]);
lua_call(L, 0, 0); lua_call(L, 0, 0);
if(alarm_timer_repeat[id]==0)
{
if(alarm_timer_cb_ref[id] != LUA_NOREF)
luaL_unref(L, LUA_REGISTRYINDEX, alarm_timer_cb_ref[id]);
}
} }
void alarm_timer_cb0(void *arg){ void alarm_timer_cb0(void *arg){
...@@ -118,6 +125,7 @@ static int tmr_alarm( lua_State* L ) ...@@ -118,6 +125,7 @@ static int tmr_alarm( lua_State* L )
stack++; stack++;
if ( repeat != 1 && repeat != 0 ) if ( repeat != 1 && repeat != 0 )
return luaL_error( L, "wrong arg type" ); return luaL_error( L, "wrong arg type" );
alarm_timer_repeat[id]=repeat;
} }
// luaL_checkanyfunction(L, stack); // luaL_checkanyfunction(L, stack);
...@@ -141,6 +149,9 @@ static int tmr_stop( lua_State* L ) ...@@ -141,6 +149,9 @@ static int tmr_stop( lua_State* L )
MOD_CHECK_ID( tmr, id ); MOD_CHECK_ID( tmr, id );
os_timer_disarm(&(alarm_timer[id])); os_timer_disarm(&(alarm_timer[id]));
if(alarm_timer_cb_ref[id] != LUA_NOREF)
luaL_unref(L, LUA_REGISTRYINDEX, alarm_timer_cb_ref[id]);
return 0; return 0;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment