Skip to content

Always swap in generated move operator - #2055

Merged
dsnopek merged 1 commit into
godotengine:masterfrom
dsnopek:fix-dictionary-leak-in-move-operator
Sep 8, 2026
Merged

Always swap in generated move operator#2055
dsnopek merged 1 commit into
godotengine:masterfrom
dsnopek:fix-dictionary-leak-in-move-operator

Conversation

@dsnopek

@dsnopek dsnopek commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Currently, this is the code we generate for Dictionary's move operator:

Dictionary &Dictionary::operator=(Dictionary &&p_other) {
	::godot::internal::_call_builtin_constructor(_method_bindings.constructor_1, &opaque, &p_other);
	return *this;
}

It's simply overwriting the opaque with data from a new Dictionary, without cleaning up the data from the old Dictionary (whereas the usual idiom is to swap the internal data with p_other, which will get cleaned up when p_other is destructed).

It looks like this comes from #656 - there was an issue where destructing Dictionary's could lead to error spam, because of an ERR_FAIL_NULL() if a Dictionary is destructed with null data. (This code is still present in Dictionary::unref().) This null could get set in the move constructor of Dictionary because it was swapping opaque value with a zero'd out one, so a fix was added to just copy rather than the usual swap.

However, it's only in the move constructor where a Dictionary could end up with null data, but the fix made the same change to move operator!

Anyway, this PR removes the fix from the move operator, while leaving it in place for the move constructor

I haven't tested yet, but I think this fixes #2048

@dsnopek dsnopek added this to the 10.x milestone Sep 8, 2026
@dsnopek
dsnopek requested a review from a team as a code owner September 8, 2026 20:34
@dsnopek dsnopek added the bug This has been identified as a bug label Sep 8, 2026
@dsnopek

dsnopek commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

It took a little work to get the MRP from #2048 working, but I've been able to reproduce the issue, and this PR does seem to fix it for me!

@dsnopek
dsnopek merged commit 6cceaf6 into godotengine:master Sep 8, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This has been identified as a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

intersect_ray() leaks when reusing returned Dictionary

2 participants