Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit bae9f2a

Browse files
author
Ehsan Akhgari
committed
Bug 865004 - Disconnect the AudioNode from the graph before deleting it; r=bzbarsky
1 parent 723c197 commit bae9f2a

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

content/media/webaudio/AudioNode.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(AudioNode, nsDOMEventTargetHel
2323
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOutputNodes)
2424
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
2525

26-
NS_IMPL_ADDREF_INHERITED(AudioNode, nsDOMEventTargetHelper)
27-
NS_IMPL_RELEASE_INHERITED(AudioNode, nsDOMEventTargetHelper)
28-
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(AudioNode)
29-
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
30-
3126
AudioNode::AudioNode(AudioContext* aContext)
3227
: mContext(aContext)
3328
{
@@ -38,11 +33,21 @@ AudioNode::AudioNode(AudioContext* aContext)
3833

3934
AudioNode::~AudioNode()
4035
{
41-
DisconnectFromGraph();
4236
MOZ_ASSERT(mInputNodes.IsEmpty());
4337
MOZ_ASSERT(mOutputNodes.IsEmpty());
4438
}
4539

40+
NS_IMETHODIMP_(nsrefcnt)
41+
AudioNode::Release()
42+
{
43+
if (mRefCnt.get() == 1) {
44+
// We are about to be deleted, disconnect the object from the graph before
45+
// the derived type is destroyed.
46+
DisconnectFromGraph();
47+
}
48+
return nsDOMEventTargetHelper::Release();
49+
}
50+
4651
static uint32_t
4752
FindIndexOfNode(const nsTArray<AudioNode::InputNode>& aInputNodes, const AudioNode* aNode)
4853
{

content/media/webaudio/AudioNode.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ class SelfReference {
7373
class AudioNode : public nsDOMEventTargetHelper,
7474
public EnableWebAudioCheck
7575
{
76+
protected:
77+
// You can only use refcounting to delete this object
78+
virtual ~AudioNode();
79+
7680
public:
7781
explicit AudioNode(AudioContext* aContext);
78-
virtual ~AudioNode();
7982

8083
// This should be idempotent (safe to call multiple times).
8184
virtual void DestroyMediaStream();
@@ -87,7 +90,8 @@ class AudioNode : public nsDOMEventTargetHelper,
8790
return false;
8891
}
8992

90-
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
93+
NS_IMETHOD_(nsrefcnt) Release() MOZ_OVERRIDE;
94+
9195
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioNode,
9296
nsDOMEventTargetHelper)
9397

0 commit comments

Comments
 (0)