summaryrefslogtreecommitdiff
path: root/lex.c
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2019-08-04 14:21:05 +1200
committerDavid Phillips <david@sighup.nz>2019-08-04 14:24:50 +1200
commit4b1f9e2cb436e74ce6084dbc35df5f052cb701bf (patch)
tree201bf4d3cf1120ad0e9a8d3fe7b1a95c2fd3333d /lex.c
parent1c8e50028e15facaa4d31992bfc6cab9d10832e6 (diff)
downloadtoy-cpu-assembler-4b1f9e2cb436e74ce6084dbc35df5f052cb701bf.tar.xz
Wrap tests in valgrind, clean up memory leaks
Diffstat (limited to 'lex.c')
-rw-r--r--lex.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/lex.c b/lex.c
index 949425e..6ed8007 100644
--- a/lex.c
+++ b/lex.c
@@ -380,6 +380,24 @@ int lex_line(void) {
return 0;
}
+void lex_free_tok(struct token t)
+{
+ if (t.s_val)
+ free(t.s_val);
+
+}
+
+void lex_free(struct token *ts, size_t t_count)
+{
+ size_t i = 0;
+
+ for (i = 0; i < t_count; i++) {
+ lex_free_tok(ts[i]);
+ }
+
+ free(ts);
+}
+
struct token* lex(const char *filename_local, FILE *fin, size_t *len)
{
filename = filename_local;