From 28aafa709ffa40e26b4cec71171b46b05f6e28aa Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Tue, 20 Dec 2016 10:54:44 +0100 Subject: Fix an opened file leak. --- src/lexer.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/lexer.c') diff --git a/src/lexer.c b/src/lexer.c index 41d6784..5610519 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -41,6 +41,11 @@ int lexer_open(lexer_state_t *ls, const char *path, vstr_t *token) return 0; } +void lexer_close(lexer_state_t *ls) +{ + fclose(ls->fp); +} + //RETURN VALUES // <0 on error // 0 on success @@ -52,13 +57,10 @@ static int fill_buffer(lexer_state_t *ls) read = fread(ls->buf, 1, sizeof(ls->buf), ls->fp); debug("read = %zu\n", read); if (read < sizeof(ls->buf)) { - if (ferror(ls->fp)) { - fclose(ls->fp); + if (ferror(ls->fp)) return -errno; - } ls->eof = true; - fclose(ls->fp); debug("no data left, ls->fp closed\n"); } -- cgit