Skip to content

Commit

Permalink
Fixed memory leaks (#129, #130)
Browse files Browse the repository at this point in the history
Added memory leak checking to Travis script
  • Loading branch information
palemieux authored Sep 18, 2018
1 parent 9378fb5 commit f3ec105
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ matrix:
apt:
packages:
- libxerces-c-dev
- valgrind

script:
- mkdir regxmllib/build
- cd regxmllib/build
- cmake ..
- cmake --build .
- ctest .
- ctest -T memcheck .
- sudo make install

- language: java
Expand Down
2 changes: 2 additions & 0 deletions regxmllib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
1 change: 1 addition & 0 deletions regxmllib/CTestConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(MEMORYCHECK_COMMAND_OPTIONS "--show-leak-kinds=definite --leak-check=full --error-exitcode=1")
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions regxmllib/src/main/cpp/com/sandflow/smpte/klv/LocalSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ namespace rxml {

if (!t.getKey().isUL()) {

throw new KLVException("Triplet key " + rxml::to_string(t.getKey()) + " is not a UL");
throw KLVException("Triplet key " + rxml::to_string(t.getKey()) + " is not a UL");
}

UL ul = t.getKey().asUL();

if (!ul.isLocalSet()) {

throw new KLVException("Triplet with key " + rxml::to_string(t.getKey()) + " is not a Local Set");
throw KLVException("Triplet with key " + rxml::to_string(t.getKey()) + " is not a Local Set");
}

membuf mb((char*)t.getValue(), (char*)t.getValue() + t.getLength());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace rxml {

if (!t.getKey().isUL()) {

throw new MXFException("Triplet key " + rxml::to_string(t.getKey()) + " is not a UL");
throw MXFException("Triplet key " + rxml::to_string(t.getKey()) + " is not a UL");
}

UL ul = t.getKey().asUL();
Expand Down Expand Up @@ -112,7 +112,7 @@ namespace rxml {
this->essenceContainers = kis.readBatch<ULAdapter, UL>();

} catch (std::exception e) {
throw new MXFException("Error reading partition pack");
throw MXFException("Error reading partition pack");
}

}
Expand Down
2 changes: 1 addition & 1 deletion regxmllib/src/main/cpp/com/sandflow/smpte/mxf/Set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace rxml {

if (!hasInstanceUID(g)) {

throw new MXFException("Group is missing an instance ID property");
throw MXFException("Group is missing an instance ID property");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ namespace rxml {
addInformativeComment(element, err.getReason());

} else {
throw new FragmentBuilder::UnknownByteOrderError(ByteOrder_UL.to_string());
throw FragmentBuilder::UnknownByteOrderError(ByteOrder_UL.to_string());
}

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ namespace rxml {
meta_dictionary.subclassesOf[parentauid].insert(def.identification);
}

} else {

delete def_copy;

}
}

Expand All @@ -111,79 +115,81 @@ namespace rxml {
const AUID parentauid = MetaDictionary::createNormalizedAUID(def.memberOf);

meta_dictionary.membersOf[parentauid].insert(def.identification);

} else {

delete def_copy;

}


}


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) {
Definition *def_copy = new EnumerationTypeDefinition(def);

_visit(def_copy);
if (! _visit(def_copy)) delete def_copy;
}

virtual void visit(const CharacterTypeDefinition &def) {
Definition *def_copy = new CharacterTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const RenameTypeDefinition & def) {
Definition *def_copy = new RenameTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const RecordTypeDefinition & def) {
Definition *def_copy = new RecordTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const StringTypeDefinition & def) {
Definition *def_copy = new StringTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const LensSerialFloatTypeDefinition & def) {
Definition *def_copy = new LensSerialFloatTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const IntegerTypeDefinition & def) {
Definition *def_copy = new IntegerTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const StrongReferenceTypeDefinition & def) {
Definition *def_copy = new StrongReferenceTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const WeakReferenceTypeDefinition & def) {
Definition *def_copy = new WeakReferenceTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const ExtendibleEnumerationTypeDefinition & def) {
Definition *def_copy = new ExtendibleEnumerationTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const VariableArrayTypeDefinition & def) {
Expand All @@ -195,31 +201,31 @@ namespace rxml {
virtual void visit(const FixedArrayTypeDefinition & def) {
Definition *def_copy = new FixedArrayTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const OpaqueTypeDefinition & def) {
Definition *def_copy = new OpaqueTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const IndirectTypeDefinition & def) {
Definition *def_copy = new IndirectTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const StreamTypeDefinition & def) {
Definition *def_copy = new StreamTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

virtual void visit(const SetTypeDefinition & def) {
Definition *def_copy = new SetTypeDefinition(def);

_visit(def_copy);
if (!_visit(def_copy)) delete def_copy;
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ namespace rxml {

if (!membersElem) {

throw new XMLImporter::Exception("Elements property missing");
throw XMLImporter::Exception("Elements property missing");

}

Expand Down Expand Up @@ -344,7 +344,7 @@ namespace rxml {

if (!elementsElem) {

throw new XMLImporter::Exception("Elements property missing");
throw XMLImporter::Exception("Elements property missing");

}

Expand Down
4 changes: 2 additions & 2 deletions regxmllib/src/main/cpp/com/sandflow/smpte/util/AUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace rxml {
UL AUID::asUL() const {

if (!isUL()) {
throw new std::invalid_argument("AUID is not a UL");
throw std::invalid_argument("AUID is not a UL");
}

return UL(this->value);
Expand All @@ -107,7 +107,7 @@ namespace rxml {
UUID AUID::asUUID() const {

if (!isUUID()) {
throw new std::invalid_argument("AUID is not a UUID");
throw std::invalid_argument("AUID is not a UUID");
}

unsigned char tmp[16];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ int main(int argc, char **argv) {

doc->release();

delete ft;
}

/* free heap */
Expand All @@ -314,7 +315,7 @@ int main(int argc, char **argv) {

output->release();
ser->release();

delete parser;

xercesc::XMLPlatformUtils::Terminate();

Expand Down

0 comments on commit f3ec105

Please sign in to comment.