Commit 02bf0344 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

WebAudio: AudioScheduledSourceNode: Fix HasPendingActivity

HasPendingActivity() is called during garbage collection which may
happen during constructing an AudioNode. Since the handler has not been
set at this point we need to guard against derefencing null.

Bug: 937208
Change-Id: I4ee92d08c97f044aca8043443f04d751428e8455
Reviewed-on: https://chromium-review.googlesource.com/c/1495977Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636776}
parent 4df7bf75
...@@ -651,6 +651,10 @@ void AudioNode::SetHandler(scoped_refptr<AudioHandler> handler) { ...@@ -651,6 +651,10 @@ void AudioNode::SetHandler(scoped_refptr<AudioHandler> handler) {
#endif #endif
} }
bool AudioNode::ContainsHandler() const {
return handler_.get();
}
AudioHandler& AudioNode::Handler() const { AudioHandler& AudioNode::Handler() const {
return *handler_; return *handler_;
} }
......
...@@ -366,6 +366,11 @@ class MODULES_EXPORT AudioNode : public EventTargetWithInlineData { ...@@ -366,6 +366,11 @@ class MODULES_EXPORT AudioNode : public EventTargetWithInlineData {
// This should be called in a constructor. // This should be called in a constructor.
void SetHandler(scoped_refptr<AudioHandler>); void SetHandler(scoped_refptr<AudioHandler>);
// During construction time the handler may not be set properly. Since the
// garbage collector can call into HasPendingActivity() such calls need to be
// able to see whether a handle has been set.
bool ContainsHandler() const;
private: private:
void WarnIfContextClosed() const; void WarnIfContextClosed() const;
void Dispose(); void Dispose();
......
...@@ -314,7 +314,8 @@ bool AudioScheduledSourceNode::HasPendingActivity() const { ...@@ -314,7 +314,8 @@ bool AudioScheduledSourceNode::HasPendingActivity() const {
// If a node is scheduled or playing, do not collect the node prematurely // If a node is scheduled or playing, do not collect the node prematurely
// even its reference is out of scope. Then fire onended event if assigned. // even its reference is out of scope. Then fire onended event if assigned.
return GetAudioScheduledSourceHandler().IsPlayingOrScheduled(); return ContainsHandler() &&
GetAudioScheduledSourceHandler().IsPlayingOrScheduled();
} }
} // namespace blink } // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment