Skip to content

Commit

Permalink
Merge pull request #102 from amaanq/fix-leaks
Browse files Browse the repository at this point in the history
Fix memory bugs
  • Loading branch information
MDeiml authored Jun 23, 2023
2 parents 231f316 + 1fd87e0 commit 936cc84
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tree-sitter-markdown/src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ const bool paragraph_interrupt_symbols[] = {
false, // NO_INDENTED_CHUNK,
false, // ERROR,
false, // TRIGGER_ERROR,
false, // EOF,
false, // MINUS_METADATA,
false, // PLUS_METADATA,
true, // PIPE_TABLE_START,
false, // PIPE_TABLE_LINE_ENDING,
};
Expand Down Expand Up @@ -257,7 +260,6 @@ static unsigned serialize(Scanner *s, char *buffer) {
static void deserialize(Scanner *s, const char *buffer, unsigned length) {
s->open_blocks.size = 0;
s->open_blocks.capacity = 0;
s->open_blocks.items = NULL;
s->state = 0;
s->matched = 0;
s->indentation = 0;
Expand All @@ -274,7 +276,6 @@ static void deserialize(Scanner *s, const char *buffer, unsigned length) {
if (blocks_size > 0) {
size_t blocks_count = blocks_size / sizeof(Block);
s->open_blocks.capacity = roundup_32(blocks_count);
s->open_blocks.items = (Block*) malloc(sizeof(Block) * s->open_blocks.capacity);
memcpy(s->open_blocks.items, &buffer[i], blocks_size);
s->open_blocks.size = blocks_count;
}
Expand Down Expand Up @@ -1451,6 +1452,7 @@ static bool scan(Scanner *s, TSLexer *lexer, const bool *valid_symbols) {

void *tree_sitter_markdown_external_scanner_create() {
Scanner *s = (Scanner *)malloc(sizeof(Scanner));
s->open_blocks.items = (Block *)calloc(1, sizeof(Block));

assert(ATX_H6_MARKER == ATX_H1_MARKER + 5);
deserialize(s, NULL, 0);
Expand Down Expand Up @@ -1487,5 +1489,6 @@ void tree_sitter_markdown_external_scanner_deserialize(

void tree_sitter_markdown_external_scanner_destroy(void *payload) {
Scanner *scanner = (Scanner *)payload;
free(scanner->open_blocks.items);
free(scanner);
}

0 comments on commit 936cc84

Please sign in to comment.