react-native-xaml/package/Codegen
Max Benat ce9030316e
Fix memory mismanagement bug with EventAttachInfo (#268)
## 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:

1. The `EventAttachInfo` struct is being updated to hold a property
ref-counted `std::shared_ptr<XamlMetadata>` instead of a **reference**
to a `XamlMetadata` object
> In effect, the previous implementation meant that the
`EventAttachInfo` was holding on to a pointer to the `EventAttachInfo`
object, completely irrespective of the fact that it was extending
`std::enable_shared_from_this`, so it wouldn't participate in
ref-counting. This would allow the object to be destroyed even if we
_believed_ there was still a strong reference to it.
2. The `EventAttachInfo` struct is now passed **by-value** into the
`DispatchTheEvent` and code-gen'd `attachHandlers_t` functions, instead
of by-reference.
> Since the code-gen'd `attachHandlders_t` lambdas would basically just
capture the `EventAttachInfo` inside another, nested lambda (which was
provided as the callback handler for the XAML control's event), passing
by-reference was a dangerous pattern to use. Although this may all
happen on the same thread, we know that the XAML event callbacks could
happen at any point, much later in the future. So, we can't assume that
the original reference to the `EventAttachInfo` captured in the lambda
is actually still valid memory.

While, in theory, we could use `std::weak_ptr` within the
`EventAttachInfo` as perhaps a more direct replacement for how the
`EventAttachInfo&` 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.
2024-02-02 23:25:18 +00:00
..
Properties Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
Codegen.csproj upgrade sample apps to .71 2023-02-01 11:40:23 -08:00
EventArgsTypeProperties.cs Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
EventArgsTypeProperties.tt Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
Model.cs Clean up formatting, spelling, and licenses (#262) 2023-08-21 12:21:35 -07:00
Program.cs Clean up formatting, spelling, and licenses (#262) 2023-08-21 12:21:35 -07:00
SyntheticProperty.cs Clean up formatting, spelling, and licenses (#262) 2023-08-21 12:21:35 -07:00
TSEnums.cs Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
TSEnums.tt Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
TSProps.cs Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
TSProps.tt Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
TSTypes.cs Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
TSTypes.tt Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
TypeCreator.cs Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
TypeCreator.tt Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
TypeEnums.cs Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
TypeEnums.tt Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
TypeEvents.cs Fix memory mismanagement bug with EventAttachInfo (#268) 2024-02-02 23:25:18 +00:00
TypeEvents.tt Fix memory mismanagement bug with EventAttachInfo (#268) 2024-02-02 23:25:18 +00:00
TypeProperties.cs Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
TypeProperties.tt Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
Util.cs Clean up formatting, spelling, and licenses (#262) 2023-08-21 12:21:35 -07:00
VersionHeader.cs Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
VersionHeader.tt Upgrade RNX to target RN and RNW 0.72 (#261) 2023-08-02 18:14:56 +00:00
Windows.UI.Xaml.json Restore ContentDialogClosed event (#228) 2022-09-26 18:35:42 +00:00
XamlNames.cs Clean up formatting, spelling, and licenses (#262) 2023-08-21 12:21:35 -07:00