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 | f77c7a36b74be10b633a2810bd2bfffd3bebcc0f (patch) | |
tree | b6fa438c7df237c2a1e4dde5cef9fbac47374c70 | |
parent | 8fd57ace20e1e6bb59dd83ed59f513954c0aed9d (diff) | |
download | uxp-f77c7a36b74be10b633a2810bd2bfffd3bebcc0f.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 4cbebe29b4..23195c3a7b 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 c76d9382b1..85d0d42e97 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; |