From b85c25e4e500d52a09a91b4664618d765dcb5358 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 2 Jun 2018 20:59:11 +0200 Subject: [PATCH] Fix resource leak. Closes: #75 --- lang/cem/libcc.ansi/misc/termcap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lang/cem/libcc.ansi/misc/termcap.c b/lang/cem/libcc.ansi/misc/termcap.c index 2916252f9..92629fd4d 100644 --- a/lang/cem/libcc.ansi/misc/termcap.c +++ b/lang/cem/libcc.ansi/misc/termcap.c @@ -58,6 +58,7 @@ int tgetent(char* bp, const char* name) } else file = "/etc/termcap"; + if ((fp = fopen(file, "r")) == (FILE*)NULL) return (-1); while (fgets(buf, 1024, fp) != NULL) @@ -66,7 +67,7 @@ int tgetent(char* bp, const char* name) continue; while (*(cp = &buf[strlen(buf) - 2]) == '\\') if (fgets(cp, 1024, fp) == NULL) - return (0); + goto exit; if (match_name(buf, name)) { strcpy(bp, buf); @@ -74,6 +75,7 @@ int tgetent(char* bp, const char* name) return (check_for_tc()); } } +exit: fclose(fp); return (0); }