]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lua nitpicks: memory management
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 7 Jul 2017 12:59:13 +0000 (14:59 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 7 Jul 2017 13:17:25 +0000 (15:17 +0200)
daemon/lua/kres.lua.in
modules/dns64/dns64.lua

index f302a08a31fd583e1353ce6f96dd9f4d115c7b98..994c3796d6b9f53bccc1aec99c34980353729119 100644 (file)
@@ -135,6 +135,8 @@ local rrset_buflen = (64 + 1) * 1024
 local rrset_buf = ffi.new('char[?]', rrset_buflen)
 local knot_rrset_t = ffi.typeof('knot_rrset_t')
 ffi.metatype( knot_rrset_t, {
+       -- beware: `owner` and `rdata` are typed as a plain lua strings
+       --         and not the real types they represent.
        __index = {
                owner = function(rr) return ffi.string(rr._owner, knot.knot_dname_size(rr._owner)) end,
                ttl = function(rr) return tonumber(knot.knot_rrset_ttl(rr)) end,
@@ -317,7 +319,7 @@ local function rr2str(rr, style)
        -- Construct a single-RR temporary set while minimizing copying.
        local rrs = knot_rrset_t()
        knot.knot_rrset_init_empty(rrs)
-       rrs._owner = ffi.cast('char *', rr.owner) -- explicit cast needed here
+       rrs._owner = ffi.cast('knot_dname_t *', rr.owner) -- explicit cast needed here
        rrs.type = rr.type
        rrs.rclass = kres.class.IN
        knot.knot_rrset_add_rdata(rrs, rr.rdata, #rr.rdata, rr.ttl, nil)
index 206daa053c7c55a50d07c12834ed18804fc1d813..e9c830b262bd88fd2183a7578017d10d44d4af46 100644 (file)
@@ -30,7 +30,7 @@ mod.layer = {
                                if orig.type == kres.type.A then
                                        local rrs = ffi.typeof('knot_rrset_t')()
                                        ffi.C.knot_rrset_init_empty(rrs)
-                                       rrs._owner = ffi.cast('char *', orig:owner()) -- explicit cast needed here
+                                       rrs._owner = ffi.cast('knot_dname_t *', orig:owner()) -- explicit cast needed here
                                        rrs.type = kres.type.AAAA
                                        rrs.rclass = orig.rclass
                                        for k = 1, orig.rrs.rr_count do
@@ -39,6 +39,8 @@ mod.layer = {
                                                ffi.copy(addr_buf + 12, rdata, 4)
                                                ffi.C.knot_rrset_add_rdata(rrs, ffi.string(addr_buf, 16), 16, orig:ttl(), req.pool)
                                        end
+                                       -- All referred memory is copied within the function,
+                                       -- so it doesn't matter that lua GCs our variables.
                                        ffi.C.kr_ranked_rrarray_add(
                                                req.answ_selected,
                                                rrs,