From 3b2611bb1b4004bb39df77050f1e31fbf73b084d Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 1 Aug 2026 00:02:00 +0300 Subject: better token cleanup --- src/fwdscript.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/fwdscript.c b/src/fwdscript.c index 1c9cff2..c197e2f 100644 --- a/src/fwdscript.c +++ b/src/fwdscript.c @@ -419,18 +419,31 @@ static int fwdscript_tokenize(struct fwdtokens *tokens, const char *buf) return 0; } +static void free_tokens(struct fwdtokens *tokens) +{ + foreach(fwdtokens, token, tokens) { + switch (token->kind) { + case FWDTOKEN_STR: + case FWDTOKEN_ID: free(token->s); + default: break; + } + } + + fwdtokens_destroy(tokens); +} + static int fwdscript_parse(struct fwdscript *s, const char *buf) { struct fwdtokens tokens = fwdtokens_create(0); if (fwdscript_tokenize(&tokens, buf)) { - fwdtokens_destroy(&tokens); + free_tokens(&tokens); return -1; } /* convert tokens into some kind of structure */ TODO(); - fwdtokens_destroy(&tokens); + free_tokens(&tokens); return 0; } -- cgit v1.3