From 205569c8d271c9446285bdf0caf92d8255bc60bc Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Sun, 14 Sep 2014 18:03:27 +0100 Subject: [PATCH] Fix various memleaks in the tests --- tests/test_aiff.cpp | 1 + tests/test_fileref.cpp | 2 ++ tests/test_flac.cpp | 2 ++ tests/test_id3v2.cpp | 2 ++ tests/test_mp4.cpp | 3 +++ tests/test_riff.cpp | 2 ++ tests/utils.h | 5 ++++- 7 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_aiff.cpp b/tests/test_aiff.cpp index df1c5ac1..00a12088 100644 --- a/tests/test_aiff.cpp +++ b/tests/test_aiff.cpp @@ -24,6 +24,7 @@ public: RIFF::AIFF::File *f = new RIFF::AIFF::File(filename.c_str()); CPPUNIT_ASSERT_EQUAL(705, f->audioProperties()->bitrate()); + delete f; } }; diff --git a/tests/test_fileref.cpp b/tests/test_fileref.cpp index 197a9213..f13eafaa 100644 --- a/tests/test_fileref.cpp +++ b/tests/test_fileref.cpp @@ -136,6 +136,7 @@ public: FileRef *f = new FileRef(TEST_FILE_PATH_C("empty_flac.oga")); CPPUNIT_ASSERT(dynamic_cast(f->file()) == NULL); CPPUNIT_ASSERT(dynamic_cast(f->file()) != NULL); + delete f; } void testOGA_Vorbis() @@ -143,6 +144,7 @@ public: FileRef *f = new FileRef(TEST_FILE_PATH_C("empty_vorbis.oga")); CPPUNIT_ASSERT(dynamic_cast(f->file()) != NULL); CPPUNIT_ASSERT(dynamic_cast(f->file()) == NULL); + delete f; } void testAPE() diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp index 22bbc854..f99a679a 100644 --- a/tests/test_flac.cpp +++ b/tests/test_flac.cpp @@ -69,6 +69,8 @@ public: CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType()); CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(150), pic->data().size()); + + delete f; } void testAddPicture() diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index a77e46af..1f080a1a 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -207,6 +207,8 @@ public: CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), frame->mimeType()); CPPUNIT_ASSERT_EQUAL(ID3v2::AttachedPictureFrame::FileIcon, frame->type()); CPPUNIT_ASSERT_EQUAL(String("d"), frame->description()); + + delete frame; } void testDontRender22() diff --git a/tests/test_mp4.cpp b/tests/test_mp4.cpp index 9b90eed3..7e25f996 100644 --- a/tests/test_mp4.cpp +++ b/tests/test_mp4.cpp @@ -142,6 +142,7 @@ public: CPPUNIT_ASSERT_EQUAL(String("82,164"), f->tag()->itemListMap()["----:com.apple.iTunes:replaygain_track_minmax"].toStringList()[0]); CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f->tag()->artist()); CPPUNIT_ASSERT_EQUAL(String("foo"), f->tag()->comment()); + delete f; } void test64BitAtom() @@ -158,6 +159,7 @@ public: f->tag()->itemListMap()["pgap"] = true; f->save(); + delete atoms; delete f; f = new MP4::File(filename.c_str()); @@ -168,6 +170,7 @@ public: moov = atoms->atoms[0]; // original size + 'pgap' size + padding CPPUNIT_ASSERT_EQUAL(long(77 + 25 + 974), moov->length); + delete atoms; delete f; } diff --git a/tests/test_riff.cpp b/tests/test_riff.cpp index 9b07a7ce..19bff169 100644 --- a/tests/test_riff.cpp +++ b/tests/test_riff.cpp @@ -86,6 +86,8 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2)); CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f->chunkData(2)); + + delete f; } void testLastChunkAtEvenPosition() diff --git a/tests/utils.h b/tests/utils.h index 5f2f9814..dfe6c4c3 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -11,6 +11,7 @@ #include #endif #include +#include #include #include #include @@ -26,7 +27,9 @@ inline string testFilePath(const string &filename) inline string copyFile(const string &filename, const string &ext) { - string newname = string(tempnam(NULL, NULL)) + ext; + char *newname_c = tempnam(NULL, NULL); + string newname = string(newname_c) + ext; + free(newname_c); string oldname = testFilePath(filename) + ext; #ifdef _WIN32 CopyFileA(oldname.c_str(), newname.c_str(), FALSE);