diff options
author | Moonchild <moonchild@palemoon.org> | 2021-01-26 23:16:22 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2021-01-26 23:16:22 +0000 |
commit | 69a19733ef4a51dc2201c2705c4f2078af75cb9b (patch) | |
tree | b6fa438c7df237c2a1e4dde5cef9fbac47374c70 | |
parent | 0162656dc88403491a4635d7f7743f464905dc1a (diff) | |
download | aura-central-69a19733ef4a51dc2201c2705c4f2078af75cb9b.tar.gz |
[DOM] Store weak pointer to next parents.
-rw-r--r-- | dom/messagechannel/MessagePortParent.h | 6 | ||||
-rw-r--r-- | dom/messagechannel/MessagePortService.cpp | 11 |
2 files changed, 13 insertions, 4 deletions
diff --git a/dom/messagechannel/MessagePortParent.h b/dom/messagechannel/MessagePortParent.h index 4cbebe29b..23195c3a7 100644 --- a/dom/messagechannel/MessagePortParent.h +++ b/dom/messagechannel/MessagePortParent.h @@ -5,6 +5,7 @@ #ifndef mozilla_dom_MessagePortParent_h #define mozilla_dom_MessagePortParent_h +#include "mozilla/WeakPtr.h" #include "mozilla/dom/PMessagePortParent.h" namespace mozilla { @@ -12,7 +13,8 @@ namespace dom { class MessagePortService; -class MessagePortParent final : public PMessagePortParent +class MessagePortParent final : public PMessagePortParent, + public SupportsWeakPtr<MessagePortParent> { public: explicit MessagePortParent(const nsID& aUUID); @@ -40,6 +42,8 @@ public: const nsID& aDestinationUUID, const uint32_t& aSequenceID); + MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MessagePortParent) + private: virtual bool RecvPostMessages(nsTArray<MessagePortMessage>&& aMessages) override; diff --git a/dom/messagechannel/MessagePortService.cpp b/dom/messagechannel/MessagePortService.cpp index c76d9382b..85d0d42e9 100644 --- a/dom/messagechannel/MessagePortService.cpp +++ b/dom/messagechannel/MessagePortService.cpp @@ -9,6 +9,7 @@ #include "mozilla/ipc/BackgroundParent.h" #include "mozilla/StaticPtr.h" #include "mozilla/Unused.h" +#include "mozilla/WeakPtr.h" #include "nsTArray.h" using mozilla::ipc::AssertIsOnBackgroundThread; @@ -59,7 +60,7 @@ public: { uint32_t mSequenceID; // MessagePortParent keeps the service alive, and we don't want a cycle. - MessagePortParent* mParent; + WeakPtr<MessagePortParent> mParent; }; FallibleTArray<NextParent> mNextParents; @@ -275,9 +276,13 @@ MessagePortService::CloseAll(const nsID& aUUID, bool aForced) data->mParent->Close(); } - for (const MessagePortServiceData::NextParent& parent : data->mNextParents) { - parent.mParent->CloseAndDelete(); + for (const MessagePortServiceData::NextParent& nextParent : data->mNextParents) { + MessagePortParent* const parent = nextParent.mParent; + if (parent) { + parent->CloseAndDelete(); + } } + data->mNextParents.Clear(); nsID destinationUUID = data->mDestinationUUID; |