File 0022-writeFile-avoid-file-leak-on-errors.patch of Package fonttosfnt.20912
From 2d30328f9c5390eb38d4052028cd00bafaa151d4 Mon Sep 17 00:00:00 2001
From: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Sat, 31 Oct 2020 21:01:02 -0700
Subject: [PATCH] writeFile: avoid file leak on errors
Resolves issues found by Oracle Parfait 4.0 static analyser:
File Leak [file-ptr-leak]:
Leaked File out
at line 337 of app/fonttosfnt/write.c in function 'writeFile'.
out initialized at line 330 with fopen
File Leak [file-ptr-leak]:
Leaked File out
at line 366 of app/fonttosfnt/write.c in function 'writeFile'.
out initialized at line 330 with fopen
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
---
write.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/write.c b/write.c
index ca7c95a..e68b70c 100644
--- a/write.c
+++ b/write.c
@@ -334,7 +334,7 @@ writeFile(char *filename, FontPtr font)
current_cmap = makeCmap(font);
if(current_cmap == NULL) {
fprintf(stderr, "Couldn't build cmap.\n");
- return -1;
+ goto fail;
}
fontMetrics(font);
@@ -363,7 +363,7 @@ writeFile(char *filename, FontPtr font)
strike->indexSubTables = makeIndexSubTables(strike, current_cmap);
if(!strike->indexSubTables) {
fprintf(stderr, "Couldn't build indexSubTable.\n");
- return -1;
+ goto fail;
}
strike = strike->next;
}
@@ -449,6 +449,7 @@ writeFile(char *filename, FontPtr font)
return 0;
fail:
+ fclose(out);
unlink(filename);
return -1;
}
--
GitLab