From 15e52b9ed701bea7b37bdacc8b3898cfb9399460 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 10 Jul 2017 16:37:21 +0100 Subject: Fix memory leak in Git::throwError --- gentoobrowse-api/service/utils/git.cpp | 4 +++- gentoobrowse-api/unittests/testUtils.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gentoobrowse-api/service/utils/git.cpp b/gentoobrowse-api/service/utils/git.cpp index 52c31d1..6e2e04e 100644 --- a/gentoobrowse-api/service/utils/git.cpp +++ b/gentoobrowse-api/service/utils/git.cpp @@ -13,7 +13,9 @@ namespace Gentoo { char ** fn = backtrace_symbols(&func, 1); assert(fn); assert(*fn); - throw ::Gentoo::GitError(*fn, err, e->klass, e->message); + std::string funcName(*fn); + free(fn); + throw ::Gentoo::GitError(funcName, err, e->klass, e->message); } std::string diff --git a/gentoobrowse-api/unittests/testUtils.cpp b/gentoobrowse-api/unittests/testUtils.cpp index e89f0fb..5109d48 100644 --- a/gentoobrowse-api/unittests/testUtils.cpp +++ b/gentoobrowse-api/unittests/testUtils.cpp @@ -2,12 +2,15 @@ #include #include +#include #include using namespace Gentoo::Utils::Git; BOOST_AUTO_TEST_CASE( gitErrorMessage ) { + xmlInitParser(); + try { gitSafeGet(git_repository_open_ext, git_repository_free, "/", 0, nullptr); } @@ -19,5 +22,8 @@ BOOST_AUTO_TEST_CASE( gitErrorMessage ) BOOST_REQUIRE(ge.message.find("repository") + 1); } } + + xmlCleanupParser(); + git_libgit2_shutdown(); } -- cgit v1.2.3