Fix memory mismanagement bug with EventAttachInfo #268
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why is this change being made?
We detected a latent issue (#267) impacting the reliability of our application(s) using
react-native-xaml
which appeared to be the result of memory being used after it had previously been freed/released. Although this ocurred most often when being run under Application Verifier, it stands to reason that this issue could potentially be reproduced on any machine at any time.What is being changed?
There were two main issues here:
EventAttachInfo
struct is being updated to hold a property ref-countedstd::shared_ptr<XamlMetadata>
instead of a reference to aXamlMetadata
objectEventAttachInfo
struct is now passed by-value into theDispatchTheEvent
and code-gen'dattachHandlers_t
functions, instead of by-reference.While, in theory, we could use
std::weak_ptr
within theEventAttachInfo
as perhaps a more direct replacement for how theEventAttachInfo&
was previously being used, the minimal extra overhead of using a strong reference seems to justify reducing the risk of leaving open other latent issues or introducing new issues.Microsoft Reviewers: Open in CodeFlow