Fix resource leak.

Closes: #75
This commit is contained in:
David Given 2018-06-02 20:59:11 +02:00
parent d6e65833fb
commit b85c25e4e5

View file

@ -58,6 +58,7 @@ int tgetent(char* bp, const char* name)
} }
else else
file = "/etc/termcap"; file = "/etc/termcap";
if ((fp = fopen(file, "r")) == (FILE*)NULL) if ((fp = fopen(file, "r")) == (FILE*)NULL)
return (-1); return (-1);
while (fgets(buf, 1024, fp) != NULL) while (fgets(buf, 1024, fp) != NULL)
@ -66,7 +67,7 @@ int tgetent(char* bp, const char* name)
continue; continue;
while (*(cp = &buf[strlen(buf) - 2]) == '\\') while (*(cp = &buf[strlen(buf) - 2]) == '\\')
if (fgets(cp, 1024, fp) == NULL) if (fgets(cp, 1024, fp) == NULL)
return (0); goto exit;
if (match_name(buf, name)) if (match_name(buf, name))
{ {
strcpy(bp, buf); strcpy(bp, buf);
@ -74,6 +75,7 @@ int tgetent(char* bp, const char* name)
return (check_for_tc()); return (check_for_tc());
} }
} }
exit:
fclose(fp); fclose(fp);
return (0); return (0);
} }