From f92a1d33f574ee66b6dee5ca5fb371826751d96a Mon Sep 17 00:00:00 2001 From: Sean Dougherty Date: Mon, 1 May 2023 17:46:45 -0700 Subject: [PATCH] fix: add final freeing of Stack to freeStack --- src/clean.c | 8 ++++---- src/gdoc.c | 2 +- src/lexer.c | 3 ++- src/lexer.h | 2 +- src/parser.c | 2 +- src/tidylib.c | 6 +++--- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/clean.c b/src/clean.c index e0cd3baae..a3f94546f 100644 --- a/src/clean.c +++ b/src/clean.c @@ -1629,7 +1629,7 @@ void TY_(BQ2Div)( TidyDocImpl* doc, Node *node ) node = next ? next : TY_(pop)(stack); } - TY_(freeStack)(stack); + TY_(freeStack)(stack, doc); } @@ -2644,7 +2644,7 @@ void TY_(FixLanguageInformation)(TidyDocImpl* doc, Node* node, Bool wantXmlLang, node = next ? next : TY_(pop)(stack); } - TY_(freeStack)(stack); + TY_(freeStack)(stack, doc); } /* @@ -2754,7 +2754,7 @@ void TY_(FixAnchors)(TidyDocImpl* doc, Node *node, Bool wantName, Bool wantId) node = next ? next : TY_(pop)(stack); } - TY_(freeStack)(stack); + TY_(freeStack)(stack, doc); } /* Issue #567 - move style elements from body to head @@ -2798,7 +2798,7 @@ static void StyleToHead(TidyDocImpl* doc, Node *head, Node *node, Bool fix, int indent--; } } - TY_(freeStack)(stack); + TY_(freeStack)(stack, doc); } diff --git a/src/gdoc.c b/src/gdoc.c index 8f5f8ffd7..9d6766ef8 100644 --- a/src/gdoc.c +++ b/src/gdoc.c @@ -139,7 +139,7 @@ static void CleanNode( TidyDocImpl* doc, Node *node ) } child = next ? next : TY_(pop)(stack); } - TY_(freeStack)(stack); + TY_(freeStack)(stack, doc); } } diff --git a/src/lexer.c b/src/lexer.c index b0afccdab..cabb7047e 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -4538,11 +4538,12 @@ FUNC_UNUSED Node* TY_(peek)(Stack *stack) /** * Frees the stack when done. */ -void TY_(freeStack)(Stack *stack) +void TY_(freeStack)(Stack *stack, TidyDocImpl *doc) { TidyFree( stack->allocator, stack->firstNode ); stack->top = -1; stack->capacity = 0; stack->firstNode = NULL; stack->allocator = NULL; + TidyFree( doc->allocator, stack) } diff --git a/src/lexer.h b/src/lexer.h index 83b92ef9f..f5b288b00 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -731,7 +731,7 @@ TY_PRIVATE Node* TY_(peek)(Stack *stack); /** * Frees the stack when done. */ -TY_PRIVATE void TY_(freeStack)(Stack *stack); +TY_PRIVATE void TY_(freeStack)(Stack *stack, TidyDocImpl *doc); /** @} diff --git a/src/parser.c b/src/parser.c index fd0661133..dc67ae8ef 100644 --- a/src/parser.c +++ b/src/parser.c @@ -584,7 +584,7 @@ static void CleanSpaces(TidyDocImpl* doc, Node* node) node = next ? next : TY_(pop)(stack); } - TY_(freeStack)(stack); + TY_(freeStack)(stack, doc); } diff --git a/src/tidylib.c b/src/tidylib.c index 28ae9be6f..4a12e32f8 100644 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -1804,7 +1804,7 @@ static void TY_(CheckHTML5)( TidyDocImpl* doc, Node* node ) node = next ? next : TY_(pop)(stack); } - TY_(freeStack)(stack); + TY_(freeStack)(stack, doc); } /***************************************************************************** * END HTML5 STUFF @@ -1935,7 +1935,7 @@ static void TY_(CheckHTMLTagsAttribsVersions)( TidyDocImpl* doc, Node* node ) node = next ? next : TY_(pop)(stack); } - TY_(freeStack)(stack); + TY_(freeStack)(stack, doc); } @@ -2091,7 +2091,7 @@ void dbg_show_all_nodes( TidyDocImpl* doc, Node *node, int indent ) } } - TY_(freeStack)(stack); + TY_(freeStack)(stack, doc); } } #endif