From 3e3b5e3566a9036fd86525d62a9ad110e72861b7 Mon Sep 17 00:00:00 2001 From: Dave Watson Date: Thu, 19 Mar 2015 12:57:13 -0700 Subject: [PATCH] fix service memory leak Summary: This code is only used in a test so far. Basically it looks like Pipeline has some dependency issues - any addBack() pipelines have to be deleted *after* the main pipeline is destroyed. Ideally if the pipeline is already closed, the destruction order wouldn't matter. There is currently no removeBack() call either. This is a quick fix for the test to just delete stuff in the right order, we can discuss a better solution when @jsedgwick returns Test Plan: fbconfig --sanitize=address --with-project-version=clang:3.5 --clang folly/wangle/service && fbmake runtests Reviewed By: hans@fb.com Subscribers: trunkagent, doug, fugalh, folly-diffs@, yfeldblum, jsedgwick FB internal diff: D1903200 Tasks: 6415578 Signature: t1:1903200:1426528298:e109dcc0ec586a505a26cd95a6f20434d22cbd37 --- folly/wangle/bootstrap/ServerBootstrap-inl.h | 4 +++- folly/wangle/service/ServiceTest.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/folly/wangle/bootstrap/ServerBootstrap-inl.h b/folly/wangle/bootstrap/ServerBootstrap-inl.h index a47b4582..ac18f314 100644 --- a/folly/wangle/bootstrap/ServerBootstrap-inl.h +++ b/folly/wangle/bootstrap/ServerBootstrap-inl.h @@ -45,7 +45,9 @@ class ServerAcceptor : public Acceptor { } void notifyPendingShutdown() {} void closeWhenIdle() {} - void dropConnection() {} + void dropConnection() { + delete this; + } void dumpConnectionState(uint8_t loglevel) {} private: PipelinePtr pipeline_; diff --git a/folly/wangle/service/ServiceTest.cpp b/folly/wangle/service/ServiceTest.cpp index d54ac9ec..8c1c8314 100644 --- a/folly/wangle/service/ServiceTest.cpp +++ b/folly/wangle/service/ServiceTest.cpp @@ -127,13 +127,14 @@ TEST(Wangle, ClientServerTest) { server.bind(port); // client - ClientBootstrap client; + auto client = std::make_shared>(); ClientServiceFactory serviceFactory; - client.pipelineFactory( + client->pipelineFactory( std::make_shared>()); SocketAddress addr("127.0.0.1", port); - client.connect(addr); - auto service = serviceFactory(&client).value(); + client->connect(addr); + auto service = std::shared_ptr>( + serviceFactory(client.get()).value()); auto rep = (*service)("test"); rep.then([&](std::string value) { @@ -143,6 +144,7 @@ TEST(Wangle, ClientServerTest) { }); EventBaseManager::get()->getEventBase()->loopForever(); server.stop(); + client.reset(); } class AppendFilter : public Filter { -- 2.34.1