From 003ac3cf49c2424faf728c0a4b4c86d3675beca2 Mon Sep 17 00:00:00 2001 From: Hironori Kitagawa Date: Sun, 14 Aug 2022 07:58:42 +0900 Subject: [PATCH] fix memory leak of luatexja.jfont.append_italic() --- src/ltj-direction.lua | 6 ++++-- src/ltj-jfmglue.lua | 3 ++- src/ltj-jfont.lua | 8 ++++---- src/ltj-lineskip.lua | 3 ++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ltj-direction.lua b/src/ltj-direction.lua index 4a0ad3a..3dafb50 100644 --- a/src/ltj-direction.lua +++ b/src/ltj-direction.lua @@ -986,7 +986,9 @@ do function luatexja.direction.vsplit() local n = scan_int(); local p = to_direct(tex_getbox(n)) - split_dir_head = nil + if split_dir_head then node_free(split_dir_head); split_dir_head = nil end + if split_dir_whatsit then split_dir_watsit = nil end + split_dir_head = nil; split_dir_whatsit=nil if p then local bh = getlist(p) if getid(bh)==id_whatsit and getsubtype(bh)==sid_user and getfield(bh, 'user_id')==DIR @@ -1015,8 +1017,8 @@ do if split_dir_whatsit then -- adjust direction of 'split_keep' set_attr(split_dir_whatsit, attr_dir, ltjs.list_dir) + split_dir_whatsit=nil end - split_dir_whatsit=nil elseif gc=='preamble' then split_dir_whatsit=nil else diff --git a/src/ltj-jfmglue.lua b/src/ltj-jfmglue.lua index 3d046f0..22c32eb 100644 --- a/src/ltj-jfmglue.lua +++ b/src/ltj-jfmglue.lua @@ -1374,6 +1374,7 @@ do local attr_yablshift = luatexbase.attributes['ltj@yablshift'] local attr_tablshift = luatexbase.attributes['ltj@tablshift'] local getcount, abs, scan_keyword = tex.getcount, math.abs, token.scan_keyword + local tex_nest = tex.nest local get_current_jfont do local attr_curjfnt = luatexbase.attributes['ltj@curjfnt'] @@ -1389,7 +1390,7 @@ do -- * (X)KANJI_SKIP(_JFM): その場で値が決まっている -- * PROCESSED_BEGIN_FLAG + (X)KANJI_SKIP: 段落終了時に決める local function insert_k_skip_common(ind, name, ica, icb) - if abs(tex.nest[tex.nest.ptr].mode) ~= ltjs.hmode then return end + if abs(tex_nest[tex_nest.ptr].mode) ~= ltjs.hmode then return end local g = node_new(id_glue); set_attr(g, attr_icflag, SPECIAL_JAGLUE) local is_late = scan_keyword("late") if not is_late then diff --git a/src/ltj-jfont.lua b/src/ltj-jfont.lua index 70557c0..a09b890 100644 --- a/src/ltj-jfont.lua +++ b/src/ltj-jfont.lua @@ -1023,12 +1023,12 @@ do local is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char_direct local ensure_tex_attr = ltjb.ensure_tex_attr local node_write = node.direct.write - local font = font + local fonts, tex_nest = font.fonts, tex.nest local new_ic_kern = function(g) return node_new(id_kern,3) end local dir_tate = luatexja.dir_table.dir_tate -- EXT: italic correction function luatexja.jfont.append_italic() - local p = to_direct(tex.nest[tex.nest.ptr].tail) + local p = to_direct(tex_nest[tex_nest.ptr].tail) local TEMP = node_new(id_kern) if p and getid(p)==id_glyph then if is_ucs_in_japanese_char(p) then @@ -1040,10 +1040,10 @@ do node_write(g); ensure_tex_attr(attr_icflag, 0) else local f = getfont(p) - local h = font_getfont(f) or font.fonts[f] + local h = font_getfont(f) or fonts[f] if h then - local g = new_ic_kern() if h.characters[getchar(p)] and h.characters[getchar(p)].italic then + local g = new_ic_kern() setfield(g, 'kern', h.characters[getchar(p)].italic) node_write(g); ensure_tex_attr(attr_icflag, 0) end diff --git a/src/ltj-lineskip.lua b/src/ltj-lineskip.lua index f8b97c1..ba08285 100644 --- a/src/ltj-lineskip.lua +++ b/src/ltj-lineskip.lua @@ -78,6 +78,7 @@ local p_dummy = ltjl.p_dummy local make_dir_whatsit = luatexja.direction.make_dir_whatsit local get_dir_count = luatexja.direction.get_dir_count local node_write = node.direct.write +local tex_nest = tex.nest local function dir_adjust_append_vlist(b, loc, prev, mirrored) local old_b = to_direct(b) @@ -87,7 +88,7 @@ local function dir_adjust_append_vlist(b, loc, prev, mirrored) local bw = texget('baselineskip', false) local normal = bw - prev - getfield(new_b, mirrored and 'depth' or 'height') local lmin, adj = nil, 0 - local tail = to_direct(tex.nest[tex.nest.ptr].tail) + local tail = to_direct(tex_nest[tex_nest.ptr].tail) if p_dummy~=ltj_profiler then while tail and (id_glue<=getid(tail)) and (getid(tail)<=id_penalty) do tail = node_prev(tail) -- 2.11.0