Skip to content

Commit

Permalink
fix crash in nil handle
Browse files Browse the repository at this point in the history
Fixes #248
  • Loading branch information
Ryan Phillips committed Dec 13, 2016
1 parent ec5cc5c commit 0ca2e6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/stream.c
Expand Up @@ -24,8 +24,10 @@ static void luv_check_buf(lua_State *L, int idx, uv_buf_t *pbuf) {

static uv_stream_t* luv_check_stream(lua_State* L, int index) {
int isStream;
void *udata;
uv_stream_t* handle;
if (!(handle = *(uv_stream_t**) lua_touserdata(L, index))) { goto fail; }
if (!(udata = lua_touserdata(L, index))) { goto fail; }
if (!(handle = *(uv_stream_t**) udata)) { goto fail; }
if (!handle->data) { goto fail; }
lua_getfield(L, LUA_REGISTRYINDEX, "uv_stream");
lua_getmetatable(L, index < 0 ? index - 1 : index);
Expand Down
7 changes: 7 additions & 0 deletions tests/test-leaks.lua
Expand Up @@ -183,4 +183,11 @@ return require('lib/tap')(function (test)
server:close()
end)

test("test nil handle for writes", function(print, p, expect, uv)
local ret, err = pcall(function ()
uv.write(nil, "hello")
end)
assert(not ret)
assert(err)
end)
end)

0 comments on commit 0ca2e6a

Please sign in to comment.