platform_bootable_recovery/applypatch
Tao Bao fdec103335 applypatch: Fix a memory leak in ApplyImagePatch().
$ valgrind --leak-check=full out/host/linux-x86/nativetest64/recovery_host_test/recovery_host_test

==36755== 112 bytes in 1 blocks are definitely lost in loss record 4 of 16
==36755==    at 0x40307C4: malloc (valgrind/coregrind/m_replacemalloc/vg_replace_malloc.c:270)
==36755==    by 0x40C1669: operator new(unsigned long) (external/libcxxabi/src/cxa_new_delete.cpp:46)
==36755==    by 0x18D6A8: ApplyImagePatch(unsigned char const*, unsigned long, Value const*, std::__1::function<unsigned long (unsigned char const*, unsigned long)>, sha_state_st*, Value const*) (bootable/recovery/applypatch/imgpatch.cpp:62)
==36755==    by 0x18D02B: ApplyImagePatch(unsigned char const*, unsigned long, unsigned char const*, unsigned long, std::__1::function<unsigned long (unsigned char const*, unsigned long)>) (bootable/recovery/applypatch/imgpatch.cpp:134)
==36755==    by 0x160D15: GenerateTarget(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) (bootable/recovery/tests/component/imgdiff_test.cpp:85)
==36755==    by 0x11FA7D: verify_patched_image(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (bootable/recovery/tests/component/imgdiff_test.cpp:96)
==36755==    by 0x12966C: ImgdiffTest_zip_mode_smoke_trailer_zeros_Test::TestBody() (bootable/recovery/tests/component/imgdiff_test.cpp:295)
==36755==    by 0x235EF9: testing::Test::Run() (external/googletest/googletest/src/gtest.cc:2455)
==36755==    by 0x236CBF: testing::TestInfo::Run() (external/googletest/googletest/src/gtest.cc:2653)
==36755==    by 0x2372D6: testing::TestCase::Run() (external/googletest/googletest/src/gtest.cc:2771)
==36755==    by 0x23EEE6: testing::internal::UnitTestImpl::RunAllTests() (external/googletest/googletest/src/gtest.cc:4648)
==36755==    by 0x23EB45: testing::UnitTest::Run() (external/googletest/googletest/src/gtest.cc:2455)

std::unique_ptr<z_stream, decltype(&deflateEnd)> strm(new z_stream(), deflateEnd);

Only the internally allocated buffers inside 'strm' would be free'd by
deflateEnd(), but not 'strm' itself.

This CL fixes the issue by moving 'strm' to stack variable. Note that we
only need to call deflateEnd() on successful return of deflateInit2().

Test: recovery_host_test && recovery_component_test
Change-Id: I39b9bdf62376b8029f95cab82c8542bfcb874009
2017-10-24 12:48:36 -07:00
..
include/applypatch Move rangeset.h and print_sha1.h into otautil. 2017-10-10 15:52:11 -07:00
Android.bp otautil: Move RangeSet implementation into rangeset.cpp. 2017-10-16 11:28:18 -07:00
applypatch.cpp Move rangeset.h and print_sha1.h into otautil. 2017-10-10 15:52:11 -07:00
applypatch_main.cpp applypatch: Add testcases for applypatch executable. 2016-11-01 14:40:14 -07:00
applypatch_modes.cpp applypatch: Remove the obsolete support for "applypatch -s". 2017-04-25 21:23:12 -07:00
applypatch_modes.h applypatch: Add testcases for applypatch executable. 2016-11-01 14:40:14 -07:00
bspatch.cpp Move rangeset.h and print_sha1.h into otautil. 2017-10-10 15:52:11 -07:00
freecache.cpp Fix the improper use of LOCAL_WHOLE_STATIC_LIBRARIES. 2016-03-03 14:52:44 -08:00
imgdiff.cpp otautil: Move RangeSet implementation into rangeset.cpp. 2017-10-16 11:28:18 -07:00
imgdiff_main.cpp Add tests for imgdiff. 2016-12-19 16:53:03 -08:00
imgpatch.cpp applypatch: Fix a memory leak in ApplyImagePatch(). 2017-10-24 12:48:36 -07:00
NOTICE Add NOTICE file 2012-04-06 13:51:00 -07:00