From 1c565a1a89b41394475c4174d2c4c4986c013b38 Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 10 Jul 2016 12:09:21 +0200 Subject: [PATCH] frontend/rawfile.c, raw_write(), fix memory ownership for pl_title and pl_date avoid assigning cloned strings to pl_date/pl_title fields of multiple plots avoid excess allocation --- src/frontend/rawfile.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/frontend/rawfile.c b/src/frontend/rawfile.c index 5548385f7..312ab1dd4 100644 --- a/src/frontend/rawfile.c +++ b/src/frontend/rawfile.c @@ -288,7 +288,7 @@ raw_write(char *name, struct plot *pl, bool app, bool binary) struct plot * raw_read(char *name) { - char *title = "default title"; + char *title = NULL; char *date = NULL; struct plot *plots = NULL, *curpl = NULL; char buf[BSIZE_SP], *s, *t, *r; @@ -352,7 +352,11 @@ raw_read(char *name) { if (!date) date = copy(datestring()); curpl->pl_date = date; - curpl->pl_title = copy(title); + if (!title) + title = copy("default title"); + curpl->pl_title = title; + date = NULL; + title = NULL; flags = VF_PERMANENT; nvars = npoints = 0; } else if (ciprefix("flags:", buf)) {