diff --git a/src/lreq.c b/src/lreq.c index 94622fc4..680f5bcc 100644 --- a/src/lreq.c +++ b/src/lreq.c @@ -40,6 +40,7 @@ static luv_req_t* luv_setup_req(lua_State* L, int callback_ref) { lua_pushvalue(L, -1); data->req_ref = luaL_ref(L, LUA_REGISTRYINDEX); data->callback_ref = callback_ref; + data->data = NULL; return data; } @@ -63,5 +64,6 @@ static void luv_fulfill_req(lua_State* L, luv_req_t* data, int nargs) { static void luv_cleanup_req(lua_State* L, luv_req_t* data) { luaL_unref(L, LUA_REGISTRYINDEX, data->req_ref); luaL_unref(L, LUA_REGISTRYINDEX, data->callback_ref); + free(data->data); free(data); } diff --git a/src/schema.c b/src/schema.c new file mode 100644 index 00000000..e7b82e11 --- /dev/null +++ b/src/schema.c @@ -0,0 +1,16 @@ +/* + * Copyright 2014 The Luvit Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ diff --git a/tests/test-leaks.lua b/tests/test-leaks.lua index dd5b3be7..f64e10a6 100644 --- a/tests/test-leaks.lua +++ b/tests/test-leaks.lua @@ -58,17 +58,35 @@ return require('lib/tap')(function (test) end) end) - test("reading valid file", function (print, p, expect, uv) + test("reading file async", function (print, p, expect, uv) local mode = tonumber("644", 8) bench(uv, p, 0x500, function () - local req = assert(uv.fs_open("README.md", "r", mode, expect(function (err, fd) + local onOpen, onStat, onRead, onClose + local fd, stat + + onOpen = expect(function (err, result) + assert(not err, err) + fd = result + uv.fs_fstat(fd, onStat) + end) + + onStat = expect(function (err, result) + assert(not err, err) + stat = result + uv.fs_read(fd, stat.size, 0, onRead) + end) + + onRead = expect(function (err, data) + assert(not err, err) + assert(#data == stat.size) + uv.fs_close(fd, onClose) + end) + + onClose = expect(function (err) assert(not err, err) - local stat = assert(uv.fs_fstat(fd)) - assert(uv.fs_read(fd, stat.size, 0)) - assert(uv.fs_close(fd, expect(function (err) - assert(not err, err) - end))) - end))) + end) + + assert(uv.fs_open("README.md", "r", mode, onOpen)) end) end) @@ -76,6 +94,9 @@ return require('lib/tap')(function (test) local mode = tonumber("644", 8) bench(uv, p, 0x2000, function () local fd = assert(uv.fs_open("README.md", "r", mode)) + local stat = assert(uv.fs_fstat(fd)) + local data = assert(uv.fs_read(fd, stat.size, 0)) + assert(#data == stat.size) assert(uv.fs_close(fd)) end) end)