Looking at the implementation of luaL_checkstack, it merely calls lua_checkstack and immediately calls luaL_error if that returns false. luaL_error internally pushes 2 values on the stack without checking.
Shouldn't there be a call to lua_checkstack(L,2) somewhere in there so it can conditionally pop 2 values from the stack before proceeding?