[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to pass arguments to argv function effectively in Lua C API
- From: Peter Cawley <lua@...>
- Date: Thu, 24 Mar 2011 22:35:53 +0000
On Thu, Mar 24, 2011 at 10:28 PM, Daurnimator <quae@daurnimator.com> wrote:
> Is there something wrong with
> int params = lua_gettop(L);
> char **argv = malloc(params);
> int i;
> for (i=1;i<=params;i++) {
> argv[i-1]=luaL_checkstring(L,i);
> }
Yes:
1. The call to malloc may fail and return NULL, thus causing invalid
memory access on "argv[i-1]".
2. The calls to luaL_checkstring may throw errors, thus leaking the
memory allocated for "argv".