]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0189: Memory leak with "above" virttext and 'relativenumber' v9.1.0189
authorzeertzjq <zeertzjq@outlook.com>
Wed, 20 Mar 2024 18:49:20 +0000 (19:49 +0100)
committerChristian Brabandt <cb@256bit.org>
Wed, 20 Mar 2024 18:49:20 +0000 (19:49 +0100)
Problem:  Memory leak with "above" virtual text and 'relativenumber'.
Solution: Free "text_props" and "text_prop_idxs" before returning.
          Also fix off-by-one error causing line number to be drawn
          beyond end of window (zeertzjq).

fixes: #14239
closes: #14241

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/drawline.c
src/testdir/dumps/Test_prop_above_below_empty_6.dump [new file with mode: 0644]
src/testdir/test_textprop.vim
src/version.c

index ed02f3cab6db9bea4051180b757a4faf37dfbfbc..a8de449af4e837c23a1ac4dde846afe89b20e457 100644 (file)
@@ -1683,8 +1683,12 @@ win_line(
     {
        // skip over rows only used for virtual text above
        wlv.row += wlv.text_prop_above_count;
-       if (wlv.row > endrow)
+       if (wlv.row >= endrow)
+       {
+           vim_free(text_props);
+           vim_free(text_prop_idxs);
            return wlv.row;
+       }
        wlv.screen_row += wlv.text_prop_above_count;
     }
 #endif
diff --git a/src/testdir/dumps/Test_prop_above_below_empty_6.dump b/src/testdir/dumps/Test_prop_above_below_empty_6.dump
new file mode 100644 (file)
index 0000000..5013643
--- /dev/null
@@ -0,0 +1,16 @@
+| +0#af5f00255#ffffff0@3|-+0#0000001#ffff4012| +0#0000000#ffffff0@54
+| +0#af5f00255&@1|1| |1+0#0000000&@7| @47
+| +0#af5f00255&@3|++0#0000001#ffff4012| +0#0000000#ffffff0@54
+| +0#af5f00255&@3|-+0#0000001#ffff4012| +0#0000000#ffffff0@54
+|2+0#af5f00255&| @2> +0#0000000&@55
+| +0#af5f00255&@3|++0#0000001#ffff4012| +0#0000000#ffffff0@54
+| +0#af5f00255&@3|-+0#0000001#ffff4012| +0#0000000#ffffff0@54
+| +0#af5f00255&@1|1| |3+0#0000000&@8| @46
+| +0#af5f00255&@3|++0#0000001#ffff4012| +0#0000000#ffffff0@54
+| +0#af5f00255&@3|-+0#0000001#ffff4012| +0#0000000#ffffff0@54
+| +0#af5f00255&@1|2| | +0#0000000&@55
+| +0#af5f00255&@3|++0#0000001#ffff4012| +0#0000000#ffffff0@54
+| +0#af5f00255&@3|-+0#0000001#ffff4012| +0#0000000#ffffff0@54
+| +0#af5f00255&@3|!+0#0000001#ffff4012| +0#0000000#ffffff0@54
+|@+0#4040ff13&@2| @56
+|:+0#0000000&|c|a|l@1| |A|d@1|M|o|r|e|(|)| @26|2|,|0|-|5|7| @7|T|o|p| 
index c88b5477a19abb738ec457f4d829b5e629ed9cd4..a06f73370620ad5da5740c4ce8e08e94f93590b6 100644 (file)
@@ -3080,6 +3080,12 @@ func Test_prop_with_text_above_below_empty()
         call prop_add(ln, 0, {'type': vt, 'text': '+', 'text_align': 'below'})
       endfor
       normal G
+
+      func AddMore()
+        call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
+        call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
+        call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'})
+      endfunc
   END
   call writefile(lines, 'XscriptPropAboveBelowEmpty', 'D')
   let buf = RunVimInTerminal('-S XscriptPropAboveBelowEmpty', #{rows: 16, cols: 60})
@@ -3101,6 +3107,12 @@ func Test_prop_with_text_above_below_empty()
   call term_sendkeys(buf, "kk")
   call VerifyScreenDump(buf, 'Test_prop_above_below_empty_5', {})
 
+  " This was drawing line number over cmdline and leaking memory.
+  call term_sendkeys(buf, ":call AddMore()\<CR>")
+  call term_sendkeys(buf, "gg")
+  call term_sendkeys(buf, "j")
+  call VerifyScreenDump(buf, 'Test_prop_above_below_empty_6', {})
+
   call StopVimInTerminal(buf)
 endfunc
 
index db093a7e410d86d55f1f8fe0b1f02a95d25b623f..3affeffad7a70f838ab448fcbf892069daec8b4e 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    189,
 /**/
     188,
 /**/