Project

General

Profile

Actions

Bug #3758

closed

security::transform memory leak

Added by Junxiao Shi over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Security
Target version:
Start date:
08/31/2016
Due date:
% Done:

100%

Estimated time:
3.00 h

Description

ndn::security::transform has multiple memory leaks due to lack of virtual destructors in base classes.

Actions #1

Updated by Junxiao Shi over 8 years ago

ubuntu@m0213:/code/ndn-cxx$ valgrind --leak-check=full build/unit-tests -t Security/Transform/TestHexDecode/Basic
==32738== Memcheck, a memory error detector
==32738== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==32738== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==32738== Command: build/unit-tests -t Security/Transform/TestHexDecode/Basic
==32738== 
Running 1 test case...

*** No errors detected
==32738== 
==32738== HEAP SUMMARY:
==32738==     in use at exit: 20,152 bytes in 31 blocks
==32738==   total heap usage: 22,873 allocs, 22,842 frees, 2,682,409 bytes allocated
==32738== 
==32738== 16 bytes in 1 blocks are definitely lost in loss record 17 of 31
==32738==    at 0x402D6BC: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==32738==    by 0x854A0B5: make_unique<ndn::security::transform::StreamSink, std::basic_ostream<char, std::char_traits<char> >&> (backports.hpp:42)
==32738==    by 0x854A0B5: ndn::security::transform::streamSink(std::ostream&) (stream-sink.cpp:53)
==32738==    by 0x82CE34B: ndn::security::transform::tests::Security::Transform::TestHexDecode::Basic::test_method() (hex-decode.t.cpp:68)
==32738==    by 0x82CE958: ndn::security::transform::tests::Security::Transform::TestHexDecode::Basic_invoker() (hex-decode.t.cpp:40)
==32738==    by 0x8097311: invoke<void (*)()> (callback.hpp:56)
==32738==    by 0x8097311: boost::unit_test::ut_detail::callback0_impl_t<boost::unit_test::ut_detail::unused, void (*)()>::invoke() (callback.hpp:89)
==32738==    by 0x4342EA5: ??? (in /usr/lib/i386-linux-gnu/libboost_unit_test_framework.so.1.58.0)
==32738==    by 0x4322C00: boost::execution_monitor::catch_signals(boost::unit_test::callback0<int> const&) (in /usr/lib/i386-linux-gnu/libboost_unit_test_framework.so.1.58.0)
==32738==    by 0x432338A: boost::execution_monitor::execute(boost::unit_test::callback0<int> const&) (in /usr/lib/i386-linux-gnu/libboost_unit_test_framework.so.1.58.0)
==32738==    by 0x4343025: boost::unit_test::unit_test_monitor_t::execute_and_translate(boost::unit_test::test_case const&) (in /usr/lib/i386-linux-gnu/libboost_unit_test_framework.so.1.58.0)
==32738==    by 0x432A1E0: boost::unit_test::framework_impl::visit(boost::unit_test::test_case const&) (in /usr/lib/i386-linux-gnu/libboost_unit_test_framework.so.1.58.0)
==32738==    by 0x43619BC: boost::unit_test::traverse_test_tree(boost::unit_test::test_case const&, boost::unit_test::test_tree_visitor&) (in /usr/lib/i386-linux-gnu/libboost_unit_test_framework.so.1.58.0)
==32738==    by 0x4361A03: boost::unit_test::traverse_test_tree(unsigned long, boost::unit_test::test_tree_visitor&) (in /usr/lib/i386-linux-gnu/libboost_unit_test_framework.so.1.58.0)
==32738== 
==32738== 140 (12 direct, 128 indirect) bytes in 1 blocks are definitely lost in loss record 29 of 31
==32738==    at 0x402D6BC: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==32738==    by 0x853F0AF: make_unique<std::vector<unsigned char>, unsigned int&> (backports.hpp:42)
==32738==    by 0x853F0AF: ndn::security::transform::HexDecode::toBytes(unsigned char const*, unsigned int) (hex-decode.cpp:84)
==32738==    by 0x853F30A: ndn::security::transform::HexDecode::convert(unsigned char const*, unsigned int) (hex-decode.cpp:60)
==32738==    by 0x854AFE8: ndn::security::transform::Transform::doWrite(unsigned char const*, unsigned int) (transform-base.cpp:128)
==32738==    by 0x854AEB1: ndn::security::transform::Downstream::write(unsigned char const*, unsigned int) (transform-base.cpp:45)
==32738==    by 0x853E57F: ndn::security::transform::BufferSource::doPump() (buffer-source.cpp:55)
==32738==    by 0x854AA45: ndn::security::transform::Source::pump() (transform-base.cpp:161)
==32738==    by 0x854AB41: ndn::security::transform::Source::operator>>(std::unique_ptr<ndn::security::transform::Sink, std::default_delete<ndn::security::transform::Sink> >) (transform-base.cpp:181)
==32738==    by 0x82CE414: ndn::security::transform::tests::Security::Transform::TestHexDecode::Basic::test_method() (hex-decode.t.cpp:68)
==32738==    by 0x82CE958: ndn::security::transform::tests::Security::Transform::TestHexDecode::Basic_invoker() (hex-decode.t.cpp:40)
==32738==    by 0x8097311: invoke<void (*)()> (callback.hpp:56)
==32738==    by 0x8097311: boost::unit_test::ut_detail::callback0_impl_t<boost::unit_test::ut_detail::unused, void (*)()>::invoke() (callback.hpp:89)
==32738==    by 0x4342EA5: ??? (in /usr/lib/i386-linux-gnu/libboost_unit_test_framework.so.1.58.0)
==32738== 
==32738== LEAK SUMMARY:
==32738==    definitely lost: 28 bytes in 2 blocks
==32738==    indirectly lost: 128 bytes in 1 blocks
==32738==      possibly lost: 0 bytes in 0 blocks
==32738==    still reachable: 19,996 bytes in 28 blocks
==32738==         suppressed: 0 bytes in 0 blocks
==32738== Reachable blocks (those to which a pointer was found) are not shown.
==32738== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==32738== 
==32738== For counts of detected and suppressed errors, rerun with: -v
==32738== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Actions #2

Updated by Junxiao Shi over 8 years ago

  • Status changed from New to In Progress
  • Assignee set to Junxiao Shi
Actions #3

Updated by Junxiao Shi over 8 years ago

  • Status changed from In Progress to Code review
  • % Done changed from 0 to 100

https://gerrit.named-data.net/3197 fixes two problems:

  • virtual destructor is missing in Downstream and Upstream base classes, so that fields in subclasses are not properly deallocated
  • BIO_free_all should be invoked on the first BIO of a chain rather than the last BIO of the chain

After this patch, valgrind --leak-check=full build/unit-tests -t Security/Transform is not reporting any definite or indirect memory leaks.

Actions #4

Updated by Junxiao Shi over 8 years ago

  • Status changed from Code review to Closed
Actions

Also available in: Atom PDF