diff options
author | Preston Pan <preston@nullring.xyz> | 2024-01-20 17:25:39 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2024-01-20 17:25:39 -0800 |
commit | ed528f82e180084c7199ae9a1a97eb54f701bdbd (patch) | |
tree | 2e71be744e9aa14cec13dbcf3ed892230f3a87cc /src/stem.c | |
parent | 24ae9e44d6aa93d7f36746d02cb0401e8a925fde (diff) |
fix memory leak partially or fully depending on how good I am at thinking
Diffstat (limited to 'src/stem.c')
-rw-r--r-- | src/stem.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -106,6 +106,8 @@ value_t *value_copy(value_t *v) { void value_free(void *vtmp) { value_t *v = (value_t *)vtmp; + if (v == NULL) + return; if (v->type == VSTR || v->type == VWORD || v->type == VERR) { string_free(v->str_word); } @@ -245,6 +247,7 @@ value_t *parse_quote(parser_t *p) { parser_skip_whitespace(p); while (p->c != ']') { if (p->c == '\0') { + value_free(retv); parser_error(p); } array_append(retv->quote, parser_get_next(p)); @@ -255,17 +258,26 @@ value_t *parse_quote(parser_t *p) { } void parser_error(parser_t *p) { - fprintf(stderr, "PARSER ERROR!\n"); + fprintf(stderr, "PARSER ERROR: unclosed `[` or `\"` \n"); + free(PARSER->source); + ht_free(WORD_TABLE, value_free); + ht_free(FLIT, func_free); + ht_free(OBJ_TABLE, custom_free); + array_free(STACK); + free(PARSER); + array_free(EVAL_STACK); exit(1); } value_t *parse_word(parser_t *p) { value_t *retv = init_value(VWORD); string_t *s = init_string(NULL); + retv->str_word = s; if (p->c == '\\') { retv->escaped = true; parser_move(p); if (isspace(p->c) || p->c == '\0') { + value_free(retv); parser_error(p); } } @@ -273,7 +285,6 @@ value_t *parse_word(parser_t *p) { string_append(s, p->c); parser_move(p); } - retv->str_word = s; return retv; } |