vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit ebab1c00ca7129a85c51c7c9bccd0e7b42f78e18
parent 53efb5a2ac57c298493736931c7fe38aa91a08bd
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun, 18 Jan 2015 11:15:06 +0100

Do not leak memory in repeated text_filename_set calls

Diffstat:
Mtext.c | 7++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/text.c b/text.c @@ -114,7 +114,7 @@ struct Text { Action *current_action; /* action holding all file changes until a snapshot is performed */ Action *saved_action; /* the last action at the time of the save operation */ size_t size; /* current file content size in bytes */ - const char *filename; /* filename of which data was loaded */ + char *filename; /* filename of which data was loaded */ struct stat info; /* stat as proped on load time */ int fd; /* the file descriptor of the original mmap-ed data */ LineCache lines; /* mapping between absolute pos in bytes and logical line breaks */ @@ -895,7 +895,7 @@ void text_free(Text *txt) { if (txt->buf.data) munmap(txt->buf.data, txt->buf.size); - free((char*)txt->filename); + free(txt->filename); free(txt); } @@ -1199,7 +1199,8 @@ const char *text_filename_get(Text *txt) { } void text_filename_set(Text *txt, const char *filename) { - txt->filename = strdup(filename); + free(txt->filename); + txt->filename = filename ? strdup(filename) : NULL; } Regex *text_regex_new(void) {