Skip to content

Commit 5b5adf5

Browse files
committed
patch 8.0.1083: leaking memory in input part of channel
Problem: Leaking memory in input part of channel. Solution: Clear the input part of channel. Free the entry. Move failing command test to a separate file to avoid bogus leak reports clouding tests that should not leak.
1 parent 9d18961 commit 5b5adf5

6 files changed

Lines changed: 27 additions & 9 deletions

File tree

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,7 @@ test_arglist \
22652265
test_taglist \
22662266
test_tcl \
22672267
test_terminal \
2268+
test_terminal_fail \
22682269
test_textobjects \
22692270
test_timers \
22702271
test_true_false \

src/channel.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,6 +2939,7 @@ remove_from_writeque(writeq_T *wq, writeq_T *entry)
29392939
wq->wq_prev = NULL;
29402940
else
29412941
wq->wq_next->wq_prev = NULL;
2942+
vim_free(entry);
29422943
}
29432944

29442945
/*
@@ -2990,7 +2991,7 @@ channel_clear(channel_T *channel)
29902991
channel_clear_one(channel, PART_SOCK);
29912992
channel_clear_one(channel, PART_OUT);
29922993
channel_clear_one(channel, PART_ERR);
2993-
/* there is no callback or queue for PART_IN */
2994+
channel_clear_one(channel, PART_IN);
29942995
free_callback(channel->ch_callback, channel->ch_partial);
29952996
channel->ch_callback = NULL;
29962997
channel->ch_partial = NULL;

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ NEW_TESTS = test_arabic.res \
194194
test_system.res \
195195
test_tcl.res \
196196
test_terminal.res \
197+
test_terminal_fail.res \
197198
test_textobjects.res \
198199
test_undo.res \
199200
test_usercommands.res \

src/testdir/test_terminal.vim

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,6 @@ func Test_terminal_redir_file()
608608
endif
609609

610610
if has('unix')
611-
let buf = term_start('xyzabc', {'err_io': 'file', 'err_name': 'Xfile'})
612-
call term_wait(buf)
613-
call WaitFor('len(readfile("Xfile")) > 0')
614-
call assert_match('executing job failed', readfile('Xfile')[0])
615-
call WaitFor('!&modified')
616-
call delete('Xfile')
617-
bwipe
618-
619611
call writefile(['one line'], 'Xfile')
620612
let buf = term_start('cat', {'in_io': 'file', 'in_name': 'Xfile'})
621613
call term_wait(buf)

src/testdir/test_terminal_fail.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
" This test is in a separate file, because it usually causes reports for memory
2+
" leaks under valgrind. That is because when fork/exec fails memory is not
3+
" freed. Since the process exists right away it's not a real leak.
4+
5+
if !has('terminal')
6+
finish
7+
endif
8+
9+
source shared.vim
10+
11+
func Test_terminal_redir_fails()
12+
if has('unix')
13+
let buf = term_start('xyzabc', {'err_io': 'file', 'err_name': 'Xfile'})
14+
call term_wait(buf)
15+
call WaitFor('len(readfile("Xfile")) > 0')
16+
call assert_match('executing job failed', readfile('Xfile')[0])
17+
call WaitFor('!&modified')
18+
call delete('Xfile')
19+
bwipe
20+
endif
21+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1083,
772774
/**/
773775
1082,
774776
/**/

0 commit comments

Comments
 (0)