From 3ee39623d21e7241af1359f7d8b7ef199e206db0 Mon Sep 17 00:00:00 2001 From: "joi@chromium.org" Date: Wed, 29 Jun 2011 01:58:27 +0000 Subject: Fix memory leak introduced by unit test, unflake timing-dependent test. Remove exclusions for TSAN and Dr. Memory. BUG=87616,86756 TEST=net_unittests Review URL: http://codereview.chromium.org/7277011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90908 0039d316-1c4b-4281-b951-d872f2087c98 --- .../dhcp_proxy_script_fetcher_win_unittest.cc | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'net/proxy') diff --git a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc index 09ffb66..baa3f26 100644 --- a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc +++ b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc @@ -58,7 +58,9 @@ class RealFetchTester { } void RunTest() { - fetcher_->Fetch(&pac_text_, &completion_callback_); + int result = fetcher_->Fetch(&pac_text_, &completion_callback_); + if (result != ERR_IO_PENDING) + finished_ = true; } void RunTestWithCancel() { @@ -67,9 +69,12 @@ class RealFetchTester { } void RunTestWithDeferredCancel() { - RunTest(); - cancel_timer_.Start(base::TimeDelta::FromMilliseconds(1), + // Put the cancellation into the queue before even running the + // test to avoid the chance of one of the adapter fetcher worker + // threads completing before cancellation. See http://crbug.com/86756. + cancel_timer_.Start(base::TimeDelta::FromMilliseconds(0), this, &RealFetchTester::OnCancelTimer); + RunTest(); } void OnCompletion(int result) { @@ -297,6 +302,17 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin { ResetTestState(); } + virtual ~MockDhcpProxyScriptFetcherWin() { + // Delete any adapter fetcher objects we didn't hand out. + std::vector::const_iterator it + = adapter_fetchers_.begin(); + for (; it != adapter_fetchers_.end(); ++it) { + if (num_fetchers_created_-- <= 0) { + delete (*it); + } + } + } + // Adds a fetcher object to the queue of fetchers used by // |ImplCreateAdapterFetcher()|, and its name to the list of adapters // returned by ImplGetCandidateAdapterNames. @@ -347,8 +363,9 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin { int next_adapter_fetcher_index_; - // Ownership is not here; it gets transferred to the implementation - // class via ImplCreateAdapterFetcher. + // Ownership gets transferred to the implementation class via + // ImplCreateAdapterFetcher, but any objects not handed out are + // deleted on destruction. std::vector adapter_fetchers_; scoped_refptr worker_thread_; -- cgit v1.1