From f294b4d3d88eba65a5f2bd560267f538bbc75ae7 Mon Sep 17 00:00:00 2001 From: Pierre-Anthony Lemieux Date: Sun, 16 Sep 2018 10:24:04 +0200 Subject: [PATCH] Added memory leak checks to travis script Fixed KLVStream memory leaks (#129) Fixed misc memory leaks (#130) --- .travis.yml | 2 ++ regxmllib/CMakeLists.txt | 2 ++ regxmllib/CTestConfig.cmake | 1 + .../main/cpp/com/sandflow/smpte/klv/KLVStream.cpp | 2 +- .../sandflow/smpte/regxml/dict/MetaDictionary.cpp | 12 +++++++++--- .../com/sandflow/smpte/dict/MetaDictionaryTest.cpp | 3 ++- 6 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 regxmllib/CTestConfig.cmake diff --git a/.travis.yml b/.travis.yml index ed8d61e..628e643 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ matrix: apt: packages: - libxerces-c-dev + - valgrind script: - mkdir regxmllib/build @@ -12,6 +13,7 @@ matrix: - cmake .. - cmake --build . - ctest . + - ctest -T memcheck . - sudo make install - language: java diff --git a/regxmllib/CMakeLists.txt b/regxmllib/CMakeLists.txt index f0ed1c9..a000fc1 100644 --- a/regxmllib/CMakeLists.txt +++ b/regxmllib/CMakeLists.txt @@ -28,6 +28,8 @@ endforeach() enable_testing() +include(CTest) + file( GLOB_RECURSE UNIT_TESTS src/test/cpp/*.cpp ) file(COPY "src/test/resources" DESTINATION "${CMAKE_BINARY_DIR}") diff --git a/regxmllib/CTestConfig.cmake b/regxmllib/CTestConfig.cmake new file mode 100644 index 0000000..48f8be8 --- /dev/null +++ b/regxmllib/CTestConfig.cmake @@ -0,0 +1 @@ +set(MEMORYCHECK_COMMAND_OPTIONS "--show-leak-kinds=definite --leak-check=full --error-exitcode=1") diff --git a/regxmllib/src/main/cpp/com/sandflow/smpte/klv/KLVStream.cpp b/regxmllib/src/main/cpp/com/sandflow/smpte/klv/KLVStream.cpp index 2e8a6bd..a49676a 100644 --- a/regxmllib/src/main/cpp/com/sandflow/smpte/klv/KLVStream.cpp +++ b/regxmllib/src/main/cpp/com/sandflow/smpte/klv/KLVStream.cpp @@ -102,7 +102,7 @@ namespace rxml { throw std::ios_base::failure("Max BER length exceeded"); } - unsigned char *buf = new unsigned char[bersz]; + unsigned char buf[8]; this->read((char*)buf, bersz); diff --git a/regxmllib/src/main/cpp/com/sandflow/smpte/regxml/dict/MetaDictionary.cpp b/regxmllib/src/main/cpp/com/sandflow/smpte/regxml/dict/MetaDictionary.cpp index 19b1c69..706c329 100644 --- a/regxmllib/src/main/cpp/com/sandflow/smpte/regxml/dict/MetaDictionary.cpp +++ b/regxmllib/src/main/cpp/com/sandflow/smpte/regxml/dict/MetaDictionary.cpp @@ -95,6 +95,10 @@ namespace rxml { meta_dictionary.subclassesOf[parentauid].insert(def.identification); } + } else { + + delete def_copy; + } } @@ -111,6 +115,11 @@ namespace rxml { const AUID parentauid = MetaDictionary::createNormalizedAUID(def.memberOf); meta_dictionary.membersOf[parentauid].insert(def.identification); + + } else { + + delete def_copy; + } @@ -118,12 +127,9 @@ namespace rxml { virtual void visit(const PropertyAliasDefinition & def) { - Definition *def_copy = new PropertyAliasDefinition(def); - const AUID parentauid = MetaDictionary::createNormalizedAUID(def.memberOf); meta_dictionary.membersOf[parentauid].insert(def.identification); - } virtual void visit(const EnumerationTypeDefinition &def) { diff --git a/regxmllib/src/test/cpp/com/sandflow/smpte/dict/MetaDictionaryTest.cpp b/regxmllib/src/test/cpp/com/sandflow/smpte/dict/MetaDictionaryTest.cpp index 62194fa..77a7a12 100644 --- a/regxmllib/src/test/cpp/com/sandflow/smpte/dict/MetaDictionaryTest.cpp +++ b/regxmllib/src/test/cpp/com/sandflow/smpte/dict/MetaDictionaryTest.cpp @@ -302,6 +302,7 @@ int main(int argc, char **argv) { doc->release(); + delete ft; } /* free heap */ @@ -314,7 +315,7 @@ int main(int argc, char **argv) { output->release(); ser->release(); - + delete parser; xercesc::XMLPlatformUtils::Terminate();