diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-26 11:32:02 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-26 11:32:02 +0100 |
commit | 498e984690895987067743bb94ee83d49da7ecb4 (patch) | |
tree | 773ffd98aa3e085d290b60d017c31810d7f641e1 /parse.c | |
parent | Start update of types. (diff) | |
download | calp-498e984690895987067743bb94ee83d49da7ecb4.tar.gz calp-498e984690895987067743bb94ee83d49da7ecb4.tar.xz |
Fix memmory errors.
Diffstat (limited to '')
-rw-r--r-- | parse.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -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)); |