diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-30 08:33:53 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-07-30 08:33:53 +0530 |
commit | 6b618e71f577ecc3e2665717515828d1ae12927b (patch) | |
tree | 3a13d301c48b93dc3f090506be273e5bc537ffd2 | |
parent | 22b62228d0b8fe081ec6df95cf331b3d290127ab (diff) |
lexer: add directive_delete()
-rw-r--r-- | include/lexer.h | 2 | ||||
-rw-r--r-- | src/lexer.c | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/include/lexer.h b/include/lexer.h index 0da45ff..c6e9b5b 100644 --- a/include/lexer.h +++ b/include/lexer.h @@ -45,6 +45,8 @@ directive_t *find_directive(char *content, key_match_t *match); key_match_t *find_next_key(char *buffer, size_t skip); char *find_contentfor_value(list_t *content_headers, char *key); +void directive_delete(directive_t *directive); + void lexer_handle_include(directive_t *directive, key_match_t *match, char *buffer, diff --git a/src/lexer.c b/src/lexer.c index 829942a..47f76f0 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -128,6 +128,7 @@ lexer_handle_contentfor(directive_t *directive, size_t n) { directive->type = CONTENTFOR; + directive->operands = NULL; contentfor_operand_t *operands = malloc(sizeof(contentfor_operand_t)); for (size_t i = n + strlen("contentfor"); i < match->length; i++) @@ -163,8 +164,8 @@ lexer_handle_contentfor(directive_t *directive, } if (new_directive->type == ENDCONTENT) { - break; free(new_directive); + break; } free(new_directive); @@ -334,3 +335,30 @@ find_contentfor_value(list_t *content_headers, char *key) return NULL; } + +void +directive_delete(directive_t *directive) +{ + switch (directive->type) { + case EACHDO: { + eachdo_operands_t *operands = directive->operands; + free(operands->content); + free(operands->key); + free(operands); + } + case CONTENTFOR: { + contentfor_operand_t *operands = directive->operands; + free(operands->content); + free(operands->key); + free(operands); + } + case PUT: + case CONTENT: + case INCLUDE: + if (directive->operands != NULL) + free(directive->operands); + break; + default: + break; + } +} |