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

Fix StringName leaks in VariantParser #83619

Merged

Conversation

YuriSizov
Copy link
Contributor

A follow-up to #83562.

Out of remaining 38 strings, 37 were variant types, and I was able to pinpoint them to #69248. It creates a static hashmap in the method's scope, which behaves the same as all other cases addressed in #83562. I'm not sure if there is any reason to store those identifiers as string names. They are returned as strings, they are compared to strings. It's just a lot conversion all around.

But I may be wrong, so feel free to suggest alternatives!

I also noticed that in one of the WebRTC classes there was a situation similar to #74031. Seems like Fabio used the same pattern in both places, so it was worth addressing it.


This still leaves one reported orphan string:

Orphan StringName: Node (static: 5, total: 6)
StringName: 1 unclaimed string names at exit.

Unfortunately, this is a very hard issue to figure out. I can't deduce what could be keeping a reference to something so generic as a string of "Node". There is nothing obvious related to static references, be it of StringName or of HashMaps or HashSets, nor related to SNAME. The variant parser issue was created by a cast from a variable, and here it can be the same case. So using a literal to locate the offending code is impossible, and debugging through everything that ever accesses "Node" as a string name during a test cycle of opening a project doesn't paint a clear picture.

So I leave it at that. I also tried to improve messages a bit so it may be easier to debug these leaks, if they are even real leaks.

@@ -1075,7 +1075,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return ERR_PARSE_ERROR;
}

static HashMap<StringName, Variant::Type> builtin_types;
static HashMap<String, Variant::Type> builtin_types;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, I checked and confirmed that token.value used below should indeed be a String when token.type is TK_IDENTIFIER.

@akien-mga akien-mga merged commit a63bff4 into godotengine:master Oct 20, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants