Destroy peerconnections in test when they refer to on-stack mocks

Adds a function to PeerConnectionIntegrationBaseTest to stop and destroy
the caller and callee objects. This should take care of dangling pointers.

Before this change, the affected test would crash randomly - typically
detected within a few minutes of a gtest-repeat=-1 run.

After this change, it has not crashed in 15 minutes of running.

Bug: webrtc:12592
Change-Id: I9980f8974015bf2b2104fcb83c2ca0d677d03c3e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264555
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37096}
diff --git a/pc/test/integration_test_helpers.h b/pc/test/integration_test_helpers.h
index a1d3a54..e733bea 100644
--- a/pc/test/integration_test_helpers.h
+++ b/pc/test/integration_test_helpers.h
@@ -1715,6 +1715,20 @@
 
   PeerConnectionIntegrationWrapper* caller() { return caller_.get(); }
 
+  // Destroy peerconnections.
+  // This can be used to ensure that all pointers to on-stack mocks
+  // get dropped before exit.
+  void DestroyPeerConnections() {
+    if (caller_) {
+      caller_->pc()->Close();
+    }
+    if (callee_) {
+      callee_->pc()->Close();
+    }
+    caller_.reset();
+    callee_.reset();
+  }
+
   // Set the `caller_` to the `wrapper` passed in and return the
   // original `caller_`.
   PeerConnectionIntegrationWrapper* SetCallerPcWrapperAndReturnCurrent(