diff options
author | Ian Moffett <ian@osmora.org> | 2025-07-20 05:02:53 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-07-20 05:04:01 -0400 |
commit | 869f0128b4b71fc3978fdc66ebae802aa3537a95 (patch) | |
tree | d4d39240a747d2c0fa0bf6c5af73e6a49e88dd27 /usr.bin/oasm | |
parent | 255a9711d5c908f5a53f74232d750db8778a0792 (diff) |
usr: oasm: Free pointers on error paths
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'usr.bin/oasm')
-rw-r--r-- | usr.bin/oasm/lex.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/usr.bin/oasm/lex.c b/usr.bin/oasm/lex.c index afbe21d..194f09a 100644 --- a/usr.bin/oasm/lex.c +++ b/usr.bin/oasm/lex.c @@ -29,6 +29,7 @@ #include <sys/errno.h> #include <string.h> +#include <stdlib.h> #include <oasm/state.h> #include <oasm/lex.h> #include <oasm/log.h> @@ -66,6 +67,20 @@ lex_skippable(struct oasm_state *state, char c) } /* + * For cleaning up allocated sources + * during error conditions + * + * @p: Memory to free + */ +static inline void +lex_try_free(void *p) +{ + if (p != NULL) { + free(p); + } +} + +/* * Put back a token to grab later * * @c: Character to put back @@ -231,7 +246,7 @@ token_reg(char *p) int lex_tok(struct oasm_state *state, struct oasm_token *ttp) { - char *p; + char *p = NULL; char c = ' '; int tmp; tt_t tok; @@ -269,6 +284,7 @@ lex_tok(struct oasm_state *state, struct oasm_token *ttp) if ((tok = token_arith(p)) != TT_UNKNOWN) { ttp->type = tok; ttp->raw = p; + lex_try_free(p); return 0; } @@ -277,6 +293,7 @@ lex_tok(struct oasm_state *state, struct oasm_token *ttp) ttp->is_reg = 1; ttp->type = tok; ttp->raw = p; + lex_try_free(p); return 0; } @@ -284,6 +301,7 @@ lex_tok(struct oasm_state *state, struct oasm_token *ttp) if ((tok = token_operand(p)) != TT_UNKNOWN) { ttp->type = tok; ttp->raw = p; + lex_try_free(p); return 0; } oasm_err("bad token \"%s\"\n", p); |