Fixing leaked reference from SCTP transport to DTLS/ICE transport.

This was causing ICE pings to continue going out on PeerConnections
that use DataChannels, even after closing the PeerConnection.

This CL adds a two-line fix, and an integration test that will catch
this and similar issues.

Bug: webrtc:7655
Change-Id: I589a2a1aaf6433c1d65be69a1267e1b52a33534b
Reviewed-on: https://webrtc-review.googlesource.com/37145
Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21488}
diff --git a/pc/peerconnection_integrationtest.cc b/pc/peerconnection_integrationtest.cc
index abad10f..0bc68a2 100644
--- a/pc/peerconnection_integrationtest.cc
+++ b/pc/peerconnection_integrationtest.cc
@@ -3659,6 +3659,31 @@
                                   kMaxWaitForFramesMs);
 }
 
+// Test that after closing PeerConnections, they stop sending any packets (ICE,
+// DTLS, RTP...).
+TEST_F(PeerConnectionIntegrationTest, ClosingConnectionStopsPacketFlow) {
+  // Set up audio/video/data, wait for some frames to be received.
+  ASSERT_TRUE(CreatePeerConnectionWrappers());
+  ConnectFakeSignaling();
+  caller()->AddAudioVideoMediaStream();
+#ifdef HAVE_SCTP
+  caller()->CreateDataChannel();
+#endif
+  caller()->CreateAndSetAndSignalOffer();
+  ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
+  ExpectNewFramesReceivedWithWait(0, 0, kDefaultExpectedAudioFrameCount,
+                                  kDefaultExpectedAudioFrameCount,
+                                  kMaxWaitForFramesMs);
+  // Close PeerConnections.
+  caller()->pc()->Close();
+  callee()->pc()->Close();
+  // Pump messages for a second, and ensure no new packets end up sent.
+  uint32_t sent_packets_a = virtual_socket_server()->sent_packets();
+  WAIT(false, 1000);
+  uint32_t sent_packets_b = virtual_socket_server()->sent_packets();
+  EXPECT_EQ(sent_packets_a, sent_packets_b);
+}
+
 }  // namespace
 
 #endif  // if !defined(THREAD_SANITIZER)