Skip to content

Commit

Permalink
Avoid possibility of leaking an activity/service context
Browse files Browse the repository at this point in the history
The bug here was that we'd create a VideoFrameReleaseTimeHelper
using whatever context DefaultRenderersFactory has, and it would
then hold a reference to that context via DisplayManager. A leak
could then occur if the player outlived the life of the context
used to create it (which would be strange/unusual, but not
impossible).

Issue: #4249

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=198747599
  • Loading branch information
ojw28 committed Jun 5, 2018
1 parent 4ecce98 commit 7d07692
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSel
this.allowedJoiningTimeMs = allowedJoiningTimeMs;
this.maxDroppedFramesToNotify = maxDroppedFramesToNotify;
this.context = context.getApplicationContext();
frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(context);
frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(this.context);
eventDispatcher = new EventDispatcher(eventHandler, eventListener);
deviceNeedsAutoFrcWorkaround = deviceNeedsAutoFrcWorkaround();
pendingOutputStreamOffsetsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ public VideoFrameReleaseTimeHelper() {
* @param context A context from which information about the default display can be retrieved.
*/
public VideoFrameReleaseTimeHelper(@Nullable Context context) {
windowManager = context == null ? null
: (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
if (context != null) {
context = context.getApplicationContext();
windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
} else {
windowManager = null;
}
if (windowManager != null) {
displayListener = Util.SDK_INT >= 17 ? maybeBuildDefaultDisplayListenerV17(context) : null;
vsyncSampler = VSyncSampler.getInstance();
Expand Down

0 comments on commit 7d07692

Please sign in to comment.