Fix writing into closed FrameWriter when dumping video in PC framework

Bug: webrtc:10138
Change-Id: I2b8e2cac2903c957dab1170ba098880a4f0252e3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160049
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29853}
diff --git a/test/pc/e2e/peer_connection_quality_test.cc b/test/pc/e2e/peer_connection_quality_test.cc
index 9dba0f5..a5fa65a 100644
--- a/test/pc/e2e/peer_connection_quality_test.cc
+++ b/test/pc/e2e/peer_connection_quality_test.cc
@@ -1032,15 +1032,15 @@
   alice_->pc()->Close();
   bob_->pc()->Close();
 
+  alice_video_sources_.clear();
+  bob_video_sources_.clear();
+  alice_.reset();
+  bob_.reset();
+
   for (const auto& video_writer : video_writers_) {
     video_writer->Close();
   }
-
-  alice_video_sources_.clear();
-  bob_video_sources_.clear();
   video_writers_.clear();
-  alice_.reset();
-  bob_.reset();
 }
 
 test::VideoFrameWriter* PeerConnectionE2EQualityTest::MaybeCreateVideoWriter(