unittests: Free everything and check for memory leaks

Also improves error reporting.
This commit is contained in:
ZyX
2017-10-16 03:06:34 +03:00
parent c03dc13bb7
commit 252a76db80
2 changed files with 45 additions and 22 deletions

View File

@@ -315,7 +315,7 @@ local function alloc_log_new()
eq(exp, self.log)
self:clear()
end
function log:clear_tmp_allocs()
function log:clear_tmp_allocs(clear_null_frees)
local toremove = {}
local allocs = {}
for i, v in ipairs(self.log) do
@@ -327,6 +327,8 @@ local function alloc_log_new()
if v.func == 'free' then
toremove[#toremove + 1] = i
end
elseif clear_null_frees and v.args[1] == self.null then
toremove[#toremove + 1] = i
end
if v.func == 'realloc' then
allocs[tostring(v.ret)] = i
@@ -779,6 +781,12 @@ local function kvi_init(kvi)
return kvi
end
local function kvi_destroy(kvi)
if kvi.items ~= kvi.init_array then
lib.xfree(kvi.items)
end
end
local function kvi_new(ct)
return kvi_init(ffi.new(ct))
end
@@ -830,6 +838,7 @@ local module = {
sc = sc,
conv_enum = conv_enum,
array_size = array_sive,
kvi_destroy = kvi_destroy,
kvi_size = kvi_size,
kvi_init = kvi_init,
kvi_new = kvi_new,