diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2016-12-20 10:54:44 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2016-12-20 10:54:44 +0100 |
commit | 28aafa709ffa40e26b4cec71171b46b05f6e28aa (patch) | |
tree | 6d4f96e4d549fe1257c0e9471227d0ac1c49ef03 /src/lexer.c | |
parent | e68c00d7e00a330be5ca6cf249ae3476a06bfa2f (diff) |
Fix an opened file leak.
Diffstat (limited to 'src/lexer.c')
-rw-r--r-- | src/lexer.c | 10 |
1 files changed, 6 insertions, 4 deletions
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"); } |