diff options
author | Peter Wu <peter@lekensteyn.nl> | 2019-01-25 19:10:51 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2019-01-26 09:07:32 +0000 |
commit | 6fbf28f3b8659b835a608e81fc97acfd797042b6 (patch) | |
tree | 6a39cc77a968d0fdb75f2792cff44a0a00466f99 /epan | |
parent | ae6b585d518c56c5daa0243796c6321643e68ed7 (diff) |
wslua_nstime: fix memleak for bad arguments to NSTime
luaL_optinteger will raise an error when the argument is an invalid
number. Delay the allocation to avoid a leak. Fixes the
test_wslua_nstime test under ASAN.
Change-Id: I6856fd218897565a60786d820f43192b41d489f2
Reviewed-on: https://code.wireshark.org/review/31744
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/wslua/wslua_nstime.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/epan/wslua/wslua_nstime.c b/epan/wslua/wslua_nstime.c index e85a94f957..5bc32f75ac 100644 --- a/epan/wslua/wslua_nstime.c +++ b/epan/wslua/wslua_nstime.c @@ -33,12 +33,13 @@ WSLUA_CONSTRUCTOR NSTime_new(lua_State *L) { /* Creates a new NSTime object. */ #define WSLUA_OPTARG_NSTime_new_SECONDS 1 /* Seconds. */ #define WSLUA_OPTARG_NSTime_new_NSECONDS 2 /* Nano seconds. */ - NSTime nstime = (NSTime)g_malloc(sizeof(nstime_t)); + lua_Integer secs = luaL_optinteger(L,WSLUA_OPTARG_NSTime_new_SECONDS,0); + lua_Integer nsecs = luaL_optinteger(L,WSLUA_OPTARG_NSTime_new_NSECONDS,0); + NSTime nstime = g_new(nstime_t, 1); if (!nstime) return 0; - - nstime->secs = (time_t) luaL_optinteger(L,WSLUA_OPTARG_NSTime_new_SECONDS,0); - nstime->nsecs = (int) luaL_optinteger(L,WSLUA_OPTARG_NSTime_new_NSECONDS,0); + nstime->secs = (time_t) secs; + nstime->nsecs = (int) nsecs; pushNSTime(L,nstime); |