| Date: Tue, 20 Mar 2018 22:17:57 -0500
libdraw: fix some memory leaks in font handling
Diffstat:
M src/libdraw/buildfont.c | 1 +
M src/libdraw/freesubfont.c | 1 +
M src/libdraw/openfont.c | 20 ++++++++++++++------
M src/libdraw/subfontcache.c | 1 +
M src/libdraw/subfontname.c | 1 +
5 files changed, 18 insertions(+), 6 deletions(-)
--- |
| t@@ -36,6 +36,7 @@ buildfont(Display *d, char *buf, char *name)
if(fnt->name==0 || fnt->cache==0 || fnt->subf==0){
Err2:
free(fnt->name);
+ free(fnt->namespec);
free(fnt->cache);
free(fnt->subf);
free(fnt->sub); |
| t@@ -31,7 +31,7 @@ openfont1(Display *d, char *name)
{
Font *fnt;
int fd, i, n, scale;
- char *buf, *nambuf, *fname, *freename;
+ char *buf, *nambuf, *nambuf0, *fname, *freename;
nambuf = 0;
freename = nil;
t@@ -42,19 +42,21 @@ openfont1(Display *d, char *name)
nambuf = smprint("#9/font/%s", fname+14);
if(nambuf == nil)
return 0;
- nambuf = unsharp(nambuf);
+ *nambuf0 = unsharp(nambuf);
+ if(nambuf0 != nambuf)
+ free(nambuf);
+ nambuf = nambuf0;
if(nambuf == nil)
return 0;
if((fd = open(nambuf, OREAD)) < 0){
free(nambuf);
return 0;
}
- fname = nambuf;
if(scale > 1) {
- name = smprint("%d*%s", scale, fname);
+ name = smprint("%d*%s", scale, nambuf);
freename = name;
} else {
- name = fname;
+ name = nambuf;
}
}
if(fd >= 0)
t@@ -63,13 +65,17 @@ openfont1(Display *d, char *name)
fd = _fontpipe(fname+10);
n = 128*1024;
}
- if(fd < 0)
+ if(fd < 0){
+ free(nambuf);
+ free(freename);
return 0;
+ }
buf = malloc(n+1);
if(buf == 0){
close(fd);
free(nambuf);
+ free(freename);
return 0;
}
i = readn(fd, buf, n);
t@@ -77,6 +83,7 @@ openfont1(Display *d, char *name)
if(i <= 0){
free(buf);
free(nambuf);
+ free(freename);
return 0;
}
buf[i] = 0;
t@@ -224,6 +231,7 @@ openfont(Display *d, char *name)
if(!f)
return nil;
f->lodpi = f;
+ free(f->namespec);
f->namespec = namespec;
/* add to display list for when dpi changes */ |