Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
toml: Probably fixed the remaining memleak
Browse files Browse the repository at this point in the history
Memleak occured in the lexer, because we didn't invoke yylex_destroy() after finishing lexing, leaving some internal buffers allocated.
  • Loading branch information
bauhaus93 committed Jun 13, 2020
1 parent ddecf33 commit 55b6682
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/plugins/toml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- infos/needs = null base64 directoryvalue
- infos/recommends = type
- infos/placements = getstorage setstorage
- infos/status = experimental memleak unfinished nodoc
- infos/status = experimental unfinished nodoc
- infos/metadata = order comment/# comment/#/start comment/#/space type tomltype origvalue
- infos/description = This storage plugin reads and writes TOML files, using Flex and Bison.

Expand Down
1 change: 1 addition & 0 deletions src/plugins/toml/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ static int driverParse (Driver * driver)
}
initializeLexer (file);
int yyResult = yyparse (driver);
clearLexer ();
fclose (file);
return driver->errorSet == true || yyResult != 0;
}
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/toml/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ void initializeLexer(FILE * file) {
// yyin = file;
}

void clearLexer(void) {
// yy_delete_buffer(YY_CURRENT_BUFFER);
yylex_destroy();
}

static inline bool validAscii (char c)
{
return c == '\t' || (c >= 0x20 && c <= 0x7E);
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/toml/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ static int writeTree (Node * node, Writer * writer)
result |= fputc (' ', writer->f) == EOF;
}
}
ELEKTRA_ASSERT (node->type == NT_LEAF || node->type == NT_ARRAY || NT_INLINE_TABLE,
"Invalid type of list element, only NT_LEAF, NT_ARRAY or NT_INLINE_TABLE expected, but found other");
ELEKTRA_ASSERT (node->type == NT_LEAF || node->type == NT_ARRAY || node->type == NT_INLINE_TABLE ||
node->type == NT_LIST_ELEMENT,
"Invalid type of list element, only NT_LEAF, NT_ARRAY or NT_INLINE_TABLE expected, but found other: %d",
node->type);
result |= writeInlineComment (comments, true, writer);
}
else
Expand Down

0 comments on commit 55b6682

Please sign in to comment.