diff options
-rw-r--r-- | src/common.h | 1 | ||||
-rw-r--r-- | src/lexer.c | 10 | ||||
-rw-r--r-- | src/mapcat.c | 1 |
3 files changed, 8 insertions, 4 deletions
diff --git a/src/common.h b/src/common.h index 7420485..0003d43 100644 --- a/src/common.h +++ b/src/common.h @@ -74,6 +74,7 @@ typedef struct { } lexer_state_t; int lexer_open(lexer_state_t *ls, const char *path, vstr_t *token); +void lexer_close(lexer_state_t *ls); int lexer_get_token(lexer_state_t *ls); int lexer_assert(lexer_state_t *ls, const char *match, const char *desc); int lexer_assert_or_eof(lexer_state_t *ls, const char *match, const char *desc); 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"); } diff --git a/src/mapcat.c b/src/mapcat.c index d9bff86..0039608 100644 --- a/src/mapcat.c +++ b/src/mapcat.c @@ -413,6 +413,7 @@ int map_read(map_t *map, const char *path) rv = 0; out: vstr_free(&token); + lexer_close(&lexer); if (rv) map_free(map); |