diff options
| author | glepnir <glephunter@gmail.com> | 2025-08-23 05:50:30 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-22 14:50:30 -0700 |
| commit | eeba0dc2ed4eecaf40014217fa7e0eabfef992af (patch) | |
| tree | 2272890febde64cd08e04f1c311011bee3d10c41 /src/nvim | |
| parent | 586b1b2d9bcfdbc2a58a7a9c90e8f90e638173e7 (diff) | |
| download | rneovim-eeba0dc2ed4eecaf40014217fa7e0eabfef992af.tar.gz rneovim-eeba0dc2ed4eecaf40014217fa7e0eabfef992af.tar.bz2 rneovim-eeba0dc2ed4eecaf40014217fa7e0eabfef992af.zip | |
fix: memory leak from double buffer initialization in read_stdin #35413
Problem: When stdin follows files, set_curbuf() initializes buffer via
enter_buffer(), then open_buffer() initializes again, causing memory leaks.
Solution: Use readfile() directly for new buffers already initialized by
enter_buffer(), only call open_buffer() for original buffer case.
Diffstat (limited to 'src/nvim')
| -rw-r--r-- | src/nvim/main.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index b91c27349e..3bed6964ac 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1627,7 +1627,7 @@ static void read_stdin(void) if (curbuf->b_ffname) { // curbuf is already opened for a file, create a new buffer for stdin. #35269 - buf_T *newbuf = buflist_new(NULL, NULL, 0, 0); + buf_T *newbuf = buflist_new(NULL, NULL, 0, BLN_LISTED); if (newbuf == NULL) { semsg("Failed to create buffer for stdin"); return; @@ -1636,11 +1636,13 @@ static void read_stdin(void) // remember the current buffer so we can go back to it prev_buf = curbuf; set_curbuf(newbuf, 0, false); + readfile(NULL, NULL, 0, 0, (linenr_T)MAXLNUM, NULL, READ_NEW + READ_STDIN, true); + } else { + set_buflisted(true); + // Create memfile and read from stdin. + open_buffer(true, NULL, 0); } - set_buflisted(true); - // Create memfile and read from stdin. - open_buffer(true, NULL, 0); if (buf_is_empty(curbuf)) { // stdin was empty so we should wipe it (e.g. "echo file1 | xargs nvim"). #8561 // stdin buffer may be first or last ("echo foo | nvim file1 -"). #35269 |