Guard against freeing a ref of zero (#3308)

This commit is contained in:
Philip Gladstone 2020-10-13 15:43:38 -04:00 committed by GitHub
parent b9091784ae
commit 7830ae671e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -416,7 +416,9 @@ static int gpio_pulse_start(lua_State *L) {
return luaL_error( L, "missing callback" );
}
luaL_unref(L, LUA_REGISTRYINDEX, pulser->cb_ref);
if (pulser->cb_ref) {
luaL_unref(L, LUA_REGISTRYINDEX, pulser->cb_ref);
}
pulser->cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);
active_pulser = pulser;