Check os_realloc calls (#2513)
This commit is contained in:
parent
509be837a8
commit
8790924c31
|
@ -78,6 +78,7 @@ static int lcron_parsedesc(lua_State *L, char *str, struct cronent_desc *desc) {
|
||||||
static int lcron_create(lua_State *L) {
|
static int lcron_create(lua_State *L) {
|
||||||
// Check arguments
|
// Check arguments
|
||||||
char *strdesc = (char*)luaL_checkstring(L, 1);
|
char *strdesc = (char*)luaL_checkstring(L, 1);
|
||||||
|
void *newlist;
|
||||||
luaL_checkanyfunction(L, 2);
|
luaL_checkanyfunction(L, 2);
|
||||||
// Parse description
|
// Parse description
|
||||||
struct cronent_desc desc;
|
struct cronent_desc desc;
|
||||||
|
@ -93,8 +94,12 @@ static int lcron_create(lua_State *L) {
|
||||||
// Set entry
|
// Set entry
|
||||||
ud->desc = desc;
|
ud->desc = desc;
|
||||||
// Store entry
|
// Store entry
|
||||||
|
newlist = os_realloc(cronent_list, sizeof(int) * (cronent_count + 1));
|
||||||
|
if (newlist == NULL) {
|
||||||
|
return luaL_error(L, "out of memory");
|
||||||
|
}
|
||||||
lua_pushvalue(L, -1);
|
lua_pushvalue(L, -1);
|
||||||
cronent_list = os_realloc(cronent_list, sizeof(int) * (cronent_count + 1));
|
cronent_list = newlist;
|
||||||
cronent_list[cronent_count++] = luaL_ref(L, LUA_REGISTRYINDEX);
|
cronent_list[cronent_count++] = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -120,8 +125,13 @@ static int lcron_schedule(lua_State *L) {
|
||||||
ud->desc = desc;
|
ud->desc = desc;
|
||||||
size_t i = lcron_findindex(L, ud);
|
size_t i = lcron_findindex(L, ud);
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
|
void *newlist;
|
||||||
|
newlist = os_realloc(cronent_list, sizeof(int) * (cronent_count + 1));
|
||||||
|
if (newlist == NULL) {
|
||||||
|
return luaL_error(L, "out of memory");
|
||||||
|
}
|
||||||
|
cronent_list = newlist;
|
||||||
lua_pushvalue(L, 1);
|
lua_pushvalue(L, 1);
|
||||||
cronent_list = os_realloc(cronent_list, sizeof(int) * (cronent_count + 1));
|
|
||||||
cronent_list[cronent_count++] = lua_ref(L, LUA_REGISTRYINDEX);
|
cronent_list[cronent_count++] = lua_ref(L, LUA_REGISTRYINDEX);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue