From 9f6d550837e277731429a103384e19645d20796a Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Tue, 16 Mar 2021 20:54:06 +0100 Subject: [PATCH] Remove memory leaks in the SVG code --- src/frontend/com_hardcopy.c | 5 ++++- src/frontend/svg.c | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/frontend/com_hardcopy.c b/src/frontend/com_hardcopy.c index 3de71d8a1..9423f55ee 100644 --- a/src/frontend/com_hardcopy.c +++ b/src/frontend/com_hardcopy.c @@ -265,8 +265,11 @@ void com_hardcopy(wordlist *wl) } } - if (tempf && *device) + if (tempf && *device) { (void) unlink(fname); + } + + tfree(fname); /* restore previous graphics context by retrieving the previous currentgraph */ PopGraphContext(); diff --git a/src/frontend/svg.c b/src/frontend/svg.c index 35abf0df4..5f01481f5 100644 --- a/src/frontend/svg.c +++ b/src/frontend/svg.c @@ -181,16 +181,20 @@ SVG_Init(void) Cfg.ints[SVG_GRID_WIDTH] = 0; if (cp_getvar("hcopyfont", CP_STRING, &strbuf, sizeof(strbuf))) { + tfree(Cfg.strings[SVG_FONT]); Cfg.strings[SVG_FONT] = strdup(strbuf); } else if (!stropts_isset) { + tfree(Cfg.strings[SVG_FONT]); Cfg.strings[SVG_FONT] = strdup("Helvetica"); } if (cp_getvar("hcopyfontfamily", CP_STRING, &strbuf, sizeof(strbuf))) { + tfree(Cfg.strings[SVG_FONT_FAMILY]); Cfg.strings[SVG_FONT_FAMILY] = strdup(strbuf); } else if (!stropts_isset){ + tfree(Cfg.strings[SVG_FONT_FAMILY]); Cfg.strings[SVG_FONT_FAMILY] = strdup("Helvetica"); } @@ -203,8 +207,10 @@ SVG_Init(void) sprintf(colorN, "color%d", colorid); if (cp_getvar(colorN, CP_STRING, colorstring, sizeof(colorstring))) { colors[colorid] = strdup(colorstring); - if (colorid == 0) + if (colorid == 0) { + tfree(Cfg.strings[SVG_BACKGROUND]); Cfg.strings[SVG_BACKGROUND] = strdup(colors[0]); + } } else { colors[colorid] = strdup(svgcolors[colorid]); @@ -302,6 +308,8 @@ SVG_NewViewport(GRAPH *graph) /* Allocate and initialise per-graph data. */ + tfree(graph->devdep); + graph->devdep = TMALLOC(SVGdevdep, 1); ddp = DEVDEP_P(graph); ddp->lastx = ddp->lasty = -1;