From: Remi Gacogne Date: Mon, 28 May 2018 16:05:52 +0000 (+0200) Subject: rec: Fix a memory leak in the negative cache unit tests X-Git-Tag: dnsdist-1.3.1~62^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a79029f01e8a0c608d4a14423cba4e052369bf0;p=pdns rec: Fix a memory leak in the negative cache unit tests --- diff --git a/pdns/recursordist/test-negcache_cc.cc b/pdns/recursordist/test-negcache_cc.cc index aba53fa26..243179465 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); }