Skip to content

Commit

Permalink
Check os_realloc calls (#2513)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwf authored and marcelstoer committed Oct 9, 2018
1 parent 509be83 commit 8790924
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/modules/cron.c
Expand Up @@ -78,6 +78,7 @@ static int lcron_parsedesc(lua_State *L, char *str, struct cronent_desc *desc) {
static int lcron_create(lua_State *L) {
// Check arguments
char *strdesc = (char*)luaL_checkstring(L, 1);
void *newlist;
luaL_checkanyfunction(L, 2);
// Parse description
struct cronent_desc desc;
Expand All @@ -93,8 +94,12 @@ static int lcron_create(lua_State *L) {
// Set entry
ud->desc = desc;
// 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);
cronent_list = os_realloc(cronent_list, sizeof(int) * (cronent_count + 1));
cronent_list = newlist;
cronent_list[cronent_count++] = luaL_ref(L, LUA_REGISTRYINDEX);
return 1;
}
Expand All @@ -120,8 +125,13 @@ static int lcron_schedule(lua_State *L) {
ud->desc = desc;
size_t i = lcron_findindex(L, ud);
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);
cronent_list = os_realloc(cronent_list, sizeof(int) * (cronent_count + 1));
cronent_list[cronent_count++] = lua_ref(L, LUA_REGISTRYINDEX);
}
return 0;
Expand Down

0 comments on commit 8790924

Please sign in to comment.