From 498e984690895987067743bb94ee83d49da7ecb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 26 Feb 2019 11:32:02 +0100 Subject: Fix memmory errors. --- parse.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'parse.c') diff --git a/parse.c b/parse.c index ead020f8..536c3917 100644 --- a/parse.c +++ b/parse.c @@ -32,6 +32,9 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { /* * Create a content_line which we use as storage while we are * parsing. This object is constantly broken down and rebuilt. + * + * {cline,param}_key is also temporary register used during + * parsing. */ SNEW(content_line, cline); SNEW(strbuf, cline_key); @@ -46,7 +49,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { if (fold(&ctx, c) > 0) { /* Actuall end of line, handle value */ TRANSFER(CLINE_CUR_VAL(&cline), &ctx.str); - handle_kv(¶m_key, &cline, &ctx); + handle_kv(&cline_key, &cline, &ctx); p_ctx = p_key; } /* Else continue on current line */ @@ -57,11 +60,8 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { /* Border between param {key, value} */ } else if (p_ctx == p_param_name && c == '=') { - /* Create a new parameter set and push the current string - * as its key */ + /* Save the current parameter key */ TRANSFER (¶m_key, &ctx.str); - // PUSH(LLIST(param_set))(CLINE_CUR_PARAMS(&cline), ps); - p_ctx = p_param_value; /* @@ -76,7 +76,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { /* We got a parameter value, push the current string to * the current parameter set. */ if (p_ctx == p_param_value) { - /* push kv pair */ + /* save current parameter value. */ NEW(strbuf, s); TRANSFER(s, &ctx.str); @@ -84,7 +84,8 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { NEW(param_set, ps); PUSH(LLIST(strbuf))(ps, s); - PUSH(TRIE(param_set))(CLINE_CUR_PARAMS(&cline), s->mem, ps); + PUSH(TRIE(param_set))(CLINE_CUR_PARAMS(&cline), param_key.mem, ps); + strbuf_soft_reset (¶m_key); } /* @@ -128,11 +129,13 @@ int parse_file(char* filename, FILE* f, vcomponent* root) { */ TRANSFER(CLINE_CUR_VAL(&cline), &ctx.str); - handle_kv(¶m_key, &cline, &ctx); + handle_kv(&cline_key, &cline, &ctx); } FREE(content_line)(&cline); + FREE(strbuf)(&cline_key); + FREE(strbuf)(¶m_key); assert(POP(LLIST(vcomponent))(&ctx.comp_stack) == root); assert(EMPTY(LLIST(strbuf))(&ctx.key_stack)); -- cgit v1.2.3