Page MenuHomePhabricator

Fix a memory leak in DoS_tests
ClosedPublic

Authored by Fabien on May 3 2019, 20:26.

Details

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

Diff Detail

Repository
rABC Bitcoin ABC
Branch
fix_dos_memleak
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 5666
Build 9394: Bitcoin ABC Buildbot (legacy)
Build 9393: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.May 3 2019, 21:14
This revision was automatically updated to reflect the committed changes.