Menu

#1180 I've found a memory leak in json output format but I don't know how to fix it (Valgrind Analysis + source line)

Usability
open
nobody
memory leak (1)
5
2022-10-06
2022-10-06
Bha
No

Hello,

This is the valgrind diagnostic of an inform() call to get the json result of the parsing of a file:

==2985== HEAP SUMMARY:
==2985== in use at exit: 800 bytes in 4 blocks
==2985== total heap usage: 34,384 allocs, 34,380 frees, 3,675,475 bytes allocated
==2985==
==2985== 800 (432 direct, 368 indirect) bytes in 2 blocks are definitely lost in loss record 2 of 2
==2985== at 0x4836F0B: operator new(unsigned long) (vg_replace_malloc.c:422)
==2985== by 0x53EA503: MediaInfoLib::MediaInfo_Internal::Inform() (MediaInfo_Inform.cpp:407)
==2985== by 0x54092F7: MediaInfoLib::MediaInfo_Internal::Inform(std::vector<mediainfolib::mediainfo_internal*, std::allocator\\<mediainfolib::mediainfo_internal*=""> >&) (MediaInfo_Internal.cpp:2412)
==2985== by 0x5406B40: MediaInfoLib::MediaInfo_Internal::Inform(MediaInfoLib::MediaInfo_Internal) (MediaInfo_Internal.cpp:2274)
==2985== by 0x53AD201: MediaInfoLib::MediaInfo::Informabi:cxx11 (MediaInfo.cpp:150)
==2985== by 0x9794E5: onbings::bof::BofMediaDetector::ParseFile(onbings::bof::BofPath const&, onbings::bof::BofMediaDetector::ResultFormat, std::__cxx11::basic_string<char, std::char_traits\\<char="">, std::allocator\\<char> >&) (bof2d.cpp:3264)
==2985== by 0x40FBD0: Bof2d_Test_MediaDetectorParse_Test::TestBody() (ut_2d.cpp:39)
==2985== by 0x5C56E51: void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::test, void="">(testing::Test</testing::test,></char></char,>, void (testing::Test::)(), char const) (gtest.cc:2607)
==2985== by 0x5C4EDD4: void testing::internal::HandleExceptionsInMethodIfSupported<testing::test, void="">(testing::Test, void (testing::Test::)(), char const*) (gtest.cc:2643)
==2985== by 0x5C25799: testing::Test::Run() (gtest.cc:2682)</testing::test,></mediainfolib::mediainfo_internal*,>

This is where the new is made but the resulting object allocated is never freed:
its location is pushed in a container but it is never de allocated
Ztring MediaInfo_Internal::Inform()
{
...
if (XML || XML_0_7_78_MA || XML_0_7_78_MI || JSON)
{
Ztring A=Get((stream_t)StreamKind, StreamPos, __T("StreamKind"));

        Node_Current->Add_Attribute("type", A);
        if (!B.empty()) Node_Current->Add_Attribute("typeorder", B);

==MEMORY LEAK==> Node* Track=new Node();
Track->RawContent=Inform((stream_t)StreamKind, StreamPos, false).To_UTF8();
Node_Current->Childs.push_back(Track);
}

I'm not a specialist of this lib so it is quite difficult to fix it from my side.
Can someone do the magic :-) ?

Discussion


Log in to post a comment.

MongoDB Logo MongoDB