Remove memory leaks in the SVG code

This commit is contained in:
Holger Vogt 2021-03-16 20:54:06 +01:00
parent 74a615d5af
commit 9f6d550837
2 changed files with 13 additions and 2 deletions

View File

@ -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();

View File

@ -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;