From f76c640b699ea30abd6d7c017756e37159305c47 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sat, 8 Aug 2020 00:23:39 -0500 Subject: [PATCH] Memory Leak: fix low-hanging fruit --- simgear/io/http_repo_sync.cxx | 3 ++- simgear/io/test_HTTP.cxx | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/simgear/io/http_repo_sync.cxx b/simgear/io/http_repo_sync.cxx index 4d46c3c2..8206e09c 100644 --- a/simgear/io/http_repo_sync.cxx +++ b/simgear/io/http_repo_sync.cxx @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -63,7 +64,7 @@ int main(int argc, char* argv[]) } SGPath rootPath = simgear::Dir::current().path(); - HTTPRepository* repo = new HTTPRepository(rootPath, &cl); + auto repo = std::make_unique(rootPath, &cl); repo->setBaseUrl(url); repo->update(); diff --git a/simgear/io/test_HTTP.cxx b/simgear/io/test_HTTP.cxx index 7311b922..9cec75c2 100644 --- a/simgear/io/test_HTTP.cxx +++ b/simgear/io/test_HTTP.cxx @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -408,19 +409,23 @@ int main(int argc, char* argv[]) cl.setMaxConnections(1); // test URL parsing - TestRequest* tr1 = new TestRequest("http://localhost.woo.zar:2000/test1?foo=bar"); - SG_CHECK_EQUAL(tr1->scheme(), "http"); - SG_CHECK_EQUAL(tr1->hostAndPort(), "localhost.woo.zar:2000"); - SG_CHECK_EQUAL(tr1->host(), "localhost.woo.zar"); - SG_CHECK_EQUAL(tr1->port(), 2000); - SG_CHECK_EQUAL(tr1->path(), "/test1"); + { + auto tr1 = std::make_unique("http://localhost.woo.zar:2000/test1?foo=bar"); + SG_CHECK_EQUAL(tr1->scheme(), "http"); + SG_CHECK_EQUAL(tr1->hostAndPort(), "localhost.woo.zar:2000"); + SG_CHECK_EQUAL(tr1->host(), "localhost.woo.zar"); + SG_CHECK_EQUAL(tr1->port(), 2000); + SG_CHECK_EQUAL(tr1->path(), "/test1"); + } - TestRequest* tr2 = new TestRequest("http://192.168.1.1/test1/dir/thing/file.png"); - SG_CHECK_EQUAL(tr2->scheme(), "http"); - SG_CHECK_EQUAL(tr2->hostAndPort(), "192.168.1.1"); - SG_CHECK_EQUAL(tr2->host(), "192.168.1.1"); - SG_CHECK_EQUAL(tr2->port(), 80); - SG_CHECK_EQUAL(tr2->path(), "/test1/dir/thing/file.png"); + { + auto tr2 = std::make_unique("http://192.168.1.1/test1/dir/thing/file.png"); + SG_CHECK_EQUAL(tr2->scheme(), "http"); + SG_CHECK_EQUAL(tr2->hostAndPort(), "192.168.1.1"); + SG_CHECK_EQUAL(tr2->host(), "192.168.1.1"); + SG_CHECK_EQUAL(tr2->port(), 80); + SG_CHECK_EQUAL(tr2->path(), "/test1/dir/thing/file.png"); + } // basic get request {