From 9a79029f01e8a0c608d4a14423cba4e052369bf0 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 28 May 2018 18:05:52 +0200 Subject: [PATCH] rec: Fix a memory leak in the negative cache unit tests --- pdns/recursordist/test-negcache_cc.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pdns/recursordist/test-negcache_cc.cc b/pdns/recursordist/test-negcache_cc.cc index aba53fa263..2431794657 100644 --- a/pdns/recursordist/test-negcache_cc.cc +++ b/pdns/recursordist/test-negcache_cc.cc @@ -383,6 +383,14 @@ BOOST_AUTO_TEST_CASE(test_dumpToFile) { BOOST_FAIL("Unable to read a line from the temp file"); BOOST_CHECK_EQUAL(line, str); } + + if (line != nullptr) { + /* getline() allocates a buffer then called with a nullptr, + then reallocates it when needed, but we need to free the + last allocation if any. */ + free(line); + } + fclose(fp); } -- 2.47.3