From 156b6cd596cb7514ff1252731b5da18271b6980f Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sat, 5 Nov 2016 21:18:39 +0100 Subject: [PATCH] BMediaFile: fix destruction order. The fSource can point to a source with code inside a media plug-in (in particular, the HTTP source from the http_streamer plugin). However, deleting the extractor can cause the plugin to become "unreferenced" and unloaded. If we try to call code to delete the source later, we find that the code is already unloaded, and the app crashes. This happens in Web+ when navigating away from Youtube or otherwise interrupting a video while it is being played. Fixes the crashing part of #13058. --- src/kits/media/MediaFile.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/kits/media/MediaFile.cpp b/src/kits/media/MediaFile.cpp index 0afae786d8..12592bd197 100644 --- a/src/kits/media/MediaFile.cpp +++ b/src/kits/media/MediaFile.cpp @@ -469,15 +469,18 @@ BMediaFile::_UnInit() free(fTrackList); fTrackList = NULL; fTrackNum = 0; - delete fExtractor; - fExtractor = NULL; - delete fWriter; - fWriter = NULL; if (fDeleteSource) { delete fSource; fSource = NULL; fDeleteSource = false; } + // Deleting the extractor or writer can cause unloading of the plugins. + // The source must be deleted before that, because it can come from a + // plugin (for example the http_streamer) + delete fExtractor; + fExtractor = NULL; + delete fWriter; + fWriter = NULL; }