Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clone_node() doesn't duplicate nonstandard tag names #3099

Open
stevecheckoway opened this issue Jan 16, 2024 · 0 comments
Open

clone_node() doesn't duplicate nonstandard tag names #3099

stevecheckoway opened this issue Jan 16, 2024 · 0 comments
Assignees
Labels
topic/gumbo Gumbo HTML5 parser topic/memory Segfaults, memory leaks, valgrind testing, etc.

Comments

@stevecheckoway
Copy link
Contributor

While investigating #3098, I noticed that Gumbo's clone_node() function doesn't make a copy of nonstandard tag names.

I think this is the fix

diff --git a/gumbo-parser/src/parser.c b/gumbo-parser/src/parser.c
index 67812b23..c3e5e038 100644
--- a/gumbo-parser/src/parser.c
+++ b/gumbo-parser/src/parser.c
@@ -1377,6 +1377,9 @@ static GumboNode* clone_node (
   *new_node = *node;
   new_node->parent = NULL;
   new_node->index_within_parent = -1;
+
+  if (node->v.element.tag == GUMBO_TAG_UNKNOWN)
+    new_node->v.element.name = gumbo_strdup(node->v.element.name);
   // Clear the GUMBO_INSERTION_IMPLICIT_END_TAG flag, as the cloned node may
   // have a separate end tag.
   new_node->parse_flags &= ~GUMBO_INSERTION_IMPLICIT_END_TAG;

but I'd like to understand why this hasn't been causing a bunch of memory leaks first.

@stevecheckoway stevecheckoway self-assigned this Jan 16, 2024
@flavorjones flavorjones added topic/memory Segfaults, memory leaks, valgrind testing, etc. topic/gumbo Gumbo HTML5 parser labels Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/gumbo Gumbo HTML5 parser topic/memory Segfaults, memory leaks, valgrind testing, etc.
Projects
None yet
Development

No branches or pull requests

2 participants