HomePhabricator

Fix a memory leak in DoS_tests

Description

Fix a memory leak in DoS_tests

Summary:
The test creates a vector of CNode * which is never freed.
Use of a vector of std::unique_ptr<CNode> solves the issue.

Output of valgrind ./src/test/test_bitcoin --run_test=DoS_tests:
Before:

==28194== Memcheck, a memory error detector
==28194== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et
al.
==28194== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright
info
==28194== Command: ./src/test/test_bitcoin --run_test=DoS_tests
==28194==
==28194== error calling PR_SET_PTRACER, vgdb might block
Running 6 test cases...

*** No errors detected
==28194==
==28194== HEAP SUMMARY:
==28194==     in use at exit: 5,142,246 bytes in 360 blocks
==28194==   total heap usage: 75,005 allocs, 74,645 frees, 111,548,732
bytes allocated
==28194==
==28194== LEAK SUMMARY:
==28194==    definitely lost: 13,448 bytes in 9 blocks
==28194==    indirectly lost: 5,127,433 bytes in 342 blocks
==28194==      possibly lost: 0 bytes in 0 blocks
==28194==    still reachable: 1,365 bytes in 9 blocks
==28194==         suppressed: 0 bytes in 0 blocks
==28194== Rerun with --leak-check=full to see details of leaked memory
==28194==
==28194== For counts of detected and suppressed errors, rerun with: -v
==28194== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

After:

==28484== Memcheck, a memory error detector
==28484== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et
al.
==28484== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright
info
==28484== Command: ./src/test/test_bitcoin --run_test=DoS_tests
==28484==
==28484== error calling PR_SET_PTRACER, vgdb might block
Running 6 test cases...

*** No errors detected
==28484==
==28484== HEAP SUMMARY:
==28484==     in use at exit: 1,365 bytes in 9 blocks
==28484==   total heap usage: 74,996 allocs, 74,987 frees, 111,564,522
bytes allocated
==28484==
==28484== LEAK SUMMARY:
==28484==    definitely lost: 0 bytes in 0 blocks
==28484==    indirectly lost: 0 bytes in 0 blocks
==28484==      possibly lost: 0 bytes in 0 blocks
==28484==    still reachable: 1,365 bytes in 9 blocks
==28484==         suppressed: 0 bytes in 0 blocks
==28484== Rerun with --leak-check=full to see details of leaked memory
==28484==
==28484== For counts of detected and suppressed errors, rerun with: -v
==28484== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Test Plan:

./src/test/test_bitcoin -t DoS_tests

Reviewers: #bitcoin_abc, deadalnix, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D2919

Details

Provenance
FabienAuthored on May 3 2019, 20:19
FabienPushed on May 6 2019, 08:11
Reviewer
Restricted Project
Differential Revision
D2919: Fix a memory leak in DoS_tests
Parents
rABC4adac02d223b: [CMAKE] Make RelWithDebInfo the default CMake configuration
Branches
Unknown
Tags
Unknown