aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lexer.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/lexer.c b/src/lexer.c
index a04f667..24a8876 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -131,20 +131,18 @@ lexer_handle_contentfor(directive_t *directive,
buffer = content + match->length + match->offset;
key_match_t *new_match;
- directive_t *new_directive;
while (true) {
new_match = find_next_key(buffer, 0);
if (new_match == NULL) {
printf("Cannot find endcontent\n");
- free(new_directive);
free(new_match);
free(directive);
/* TODO: Handle early returns */
return;
}
- new_directive = find_directive(buffer, new_match);
+ directive_t *new_directive = find_directive(buffer, new_match);
if (new_directive == NULL) {
printf("Cannot find directive: %.*s\n",
new_match->length,
@@ -157,16 +155,17 @@ lexer_handle_contentfor(directive_t *directive,
if (new_directive->type == ENDCONTENT) {
break;
+ free(new_directive);
}
+
+ free(new_directive);
+ free(new_match);
}
operands->content = strndup(buffer, new_match->offset);
operands->length
= match->offset + match->length + new_match->offset + new_match->length;
- free(new_directive);
- free(new_match);
-
directive->operands = operands;
}
@@ -191,22 +190,19 @@ lexer_handle_for(directive_t *directive,
free(orig);
buffer += match->length;
-
key_match_t *new_match;
- directive_t *new_directive;
while (true) {
new_match = find_next_key(buffer, 0);
if (new_match == NULL) {
printf("Cannot find endfor\n");
- free(new_directive);
free(new_match);
free(directive);
/* TODO: Handle early returns */
return;
}
- new_directive = find_directive(buffer, new_match);
+ directive_t *new_directive = find_directive(buffer, new_match);
if (new_directive == NULL) {
printf("Cannot find directive: %.*s\n",
new_match->length,
@@ -218,15 +214,16 @@ lexer_handle_for(directive_t *directive,
}
if (new_directive->type == ENDFOR) {
+ free(new_directive);
break;
}
+
+ free(new_directive);
+ free(new_match);
}
operands->content = strndup(buffer, new_match->offset);
- free(new_directive);
- free(new_match);
-
printf("KEY: %s\n", operands->key);
printf("SOURCE: %s\n", operands->source);
printf("CONTENT: %s\n", operands->content);