aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-01-18 11:15:06 +0100
committerMarc André Tanner <mat@brain-dump.org>2015-01-18 11:15:06 +0100
commit272d3ef44dc28774720abd6527683860b6634149 (patch)
tree0190e827b74825702fea0e897d3977d066bf275c
parentbaacfb6a5d84f647f1e24c7ad5f2b53c436a3c78 (diff)
downloadvis-272d3ef44dc28774720abd6527683860b6634149.tar.gz
vis-272d3ef44dc28774720abd6527683860b6634149.tar.xz
Do not leak memory in repeated text_filename_set calls
-rw-r--r--text.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/text.c b/text.c
index 0516d58..71d21c4 100644
--- 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) {