wslua: Abort on out of memory

The current wslua code does not properly handle out of memory
conditions. Since recovering from OOM is difficult in many places, just
abort the program (which is done by g_realloc).

Change-Id: Idae68d08c90c82ba5df18a28cc1e507d61d20e78
Reviewed-on: https://code.wireshark.org/review/14786
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
Peter Wu 2016-04-03 00:12:32 +02:00
parent 4a37458c5d
commit c82cbfdc72
1 changed files with 9 additions and 1 deletions

View File

@ -717,6 +717,14 @@ wslua_get_expert_field(const int group, const int severity)
return &ei_lua_error;
}
static void *
wslua_allocf(void *ud _U_, void *ptr, size_t osize _U_, size_t nsize)
{
/* g_realloc frees ptr if nsize==0 and returns NULL (as desired).
* Furthermore it simplifies error handling by aborting on OOM */
return g_realloc(ptr, nsize);
}
void wslua_init(register_cb cb, gpointer client_data) {
gchar* filename;
const funnel_ops_t* ops = funnel_get_funnel_ops();
@ -831,7 +839,7 @@ void wslua_init(register_cb cb, gpointer client_data) {
}
if (!L) {
L = luaL_newstate();
L = lua_newstate(wslua_allocf, NULL);
}
WSLUA_INIT(L);