From 9492c3de18269ed3fbde6fba09b3518148786f5a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 25 Oct 2013 00:05:52 -0700 Subject: [PATCH 1/2] various memory leaks and compiler warning fixes --- libraries/shared/src/NodeList.cpp | 5 ++++- libraries/shared/src/OctalCode.cpp | 2 +- libraries/voxels/src/CoverageMap.cpp | 10 +++++----- libraries/voxels/src/VoxelNode.cpp | 13 +++++++++++++ libraries/voxels/src/VoxelTree.cpp | 1 - 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index c60898253b..fb0b5176cf 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -531,7 +531,10 @@ void NodeList::sendDomainServerCheckIn() { packetPosition += numBytesNodesOfInterest; } - _nodeSocket.send(_domainIP.toString().toLocal8Bit().constData(), _domainPort, checkInPacket, packetPosition - checkInPacket); + _nodeSocket.send(_domainIP.toString().toLocal8Bit().constData(), _domainPort, checkInPacket, + packetPosition - checkInPacket); + + delete[] checkInPacket; // clean up const int NUM_DOMAIN_SERVER_CHECKINS_PER_STUN_REQUEST = 5; static unsigned int numDomainCheckins = 0; diff --git a/libraries/shared/src/OctalCode.cpp b/libraries/shared/src/OctalCode.cpp index 80f6ba121f..c0f1ccfa62 100644 --- a/libraries/shared/src/OctalCode.cpp +++ b/libraries/shared/src/OctalCode.cpp @@ -333,7 +333,7 @@ unsigned char* hexStringToOctalCode(const QString& input) { // loop through the string - 2 bytes at a time converting // it to decimal equivalent and store in byte array - bool ok; + bool ok = false; while (stringIndex < input.length()) { uint value = input.mid(stringIndex, HEX_BYTE_SIZE).toUInt(&ok, HEX_NUMBER_BASE); if (!ok) { diff --git a/libraries/voxels/src/CoverageMap.cpp b/libraries/voxels/src/CoverageMap.cpp index 530581e5f5..21744c408a 100644 --- a/libraries/voxels/src/CoverageMap.cpp +++ b/libraries/voxels/src/CoverageMap.cpp @@ -205,7 +205,7 @@ CoverageMapStorageResult CoverageMap::checkMap(VoxelProjectedPolygon* polygon, b CoverageMapStorageResult result = NOT_STORED; CoverageRegion* storeIn = &_remainder; - bool fitsInAHalf = false; + //bool fitsInAHalf = false; // Check each half of the box independently const bool useRegions = true; // for now we will continue to use regions @@ -213,19 +213,19 @@ CoverageMapStorageResult CoverageMap::checkMap(VoxelProjectedPolygon* polygon, b if (_topHalf.contains(polygonBox)) { result = _topHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_topHalf; - fitsInAHalf = true; + //fitsInAHalf = true; } else if (_bottomHalf.contains(polygonBox)) { result = _bottomHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_bottomHalf; - fitsInAHalf = true; + //fitsInAHalf = true; } else if (_leftHalf.contains(polygonBox)) { result = _leftHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_leftHalf; - fitsInAHalf = true; + //fitsInAHalf = true; } else if (_rightHalf.contains(polygonBox)) { result = _rightHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_rightHalf; - fitsInAHalf = true; + //fitsInAHalf = true; } } diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index 40cdbe3a3b..7245d2aa56 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -324,20 +324,29 @@ VoxelNode* VoxelNode::getChildAtIndex(int childIndex) const { VoxelNode* result = NULL; int childCount = getChildCount(); +#ifdef HAS_AUDIT_CHILDREN const char* caseStr = NULL; +#endif + switch (childCount) { case 0: +#ifdef HAS_AUDIT_CHILDREN caseStr = "0 child case"; +#endif break; case 1: { +#ifdef HAS_AUDIT_CHILDREN caseStr = "1 child case"; +#endif int indexOne = getNthBit(_childBitmask, 1); if (indexOne == childIndex) { result = _children.single; } } break; case 2: { +#ifdef HAS_AUDIT_CHILDREN caseStr = "2 child case"; +#endif int indexOne = getNthBit(_childBitmask, 1); int indexTwo = getNthBit(_childBitmask, 2); @@ -358,7 +367,9 @@ VoxelNode* VoxelNode::getChildAtIndex(int childIndex) const { } } break; case 3: { +#ifdef HAS_AUDIT_CHILDREN caseStr = "3 child case"; +#endif int indexOne = getNthBit(_childBitmask, 1); int indexTwo = getNthBit(_childBitmask, 2); int indexThree = getNthBit(_childBitmask, 3); @@ -386,7 +397,9 @@ VoxelNode* VoxelNode::getChildAtIndex(int childIndex) const { } } break; default: { +#ifdef HAS_AUDIT_CHILDREN caseStr = "default"; +#endif // if we have 4 or more, we know we're in external mode, so we just need to figure out which // slot in our external array this child is. if (oneAtBit(_childBitmask, childIndex)) { diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 5e6b312b83..031d407ea0 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -1432,7 +1432,6 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp // write the child exist bits *writeToThisLevelBuffer = childrenExistInPacketBits; - writeToThisLevelBuffer += sizeof(childrenExistInPacketBits); // move the pointer bytesAtThisLevel += sizeof(childrenExistInPacketBits); // keep track of byte count if (params.stats) { params.stats->existsInPacketBitsWritten(); From 953196510f27a7151b51b0758bda2ab48dad2562 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 25 Oct 2013 00:07:34 -0700 Subject: [PATCH 2/2] removed some dead code --- libraries/voxels/src/CoverageMap.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libraries/voxels/src/CoverageMap.cpp b/libraries/voxels/src/CoverageMap.cpp index 21744c408a..d127bd5804 100644 --- a/libraries/voxels/src/CoverageMap.cpp +++ b/libraries/voxels/src/CoverageMap.cpp @@ -205,7 +205,6 @@ CoverageMapStorageResult CoverageMap::checkMap(VoxelProjectedPolygon* polygon, b CoverageMapStorageResult result = NOT_STORED; CoverageRegion* storeIn = &_remainder; - //bool fitsInAHalf = false; // Check each half of the box independently const bool useRegions = true; // for now we will continue to use regions @@ -213,19 +212,15 @@ CoverageMapStorageResult CoverageMap::checkMap(VoxelProjectedPolygon* polygon, b if (_topHalf.contains(polygonBox)) { result = _topHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_topHalf; - //fitsInAHalf = true; } else if (_bottomHalf.contains(polygonBox)) { result = _bottomHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_bottomHalf; - //fitsInAHalf = true; } else if (_leftHalf.contains(polygonBox)) { result = _leftHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_leftHalf; - //fitsInAHalf = true; } else if (_rightHalf.contains(polygonBox)) { result = _rightHalf.checkRegion(polygon, polygonBox, storeIt); storeIn = &_rightHalf; - //fitsInAHalf = true; } }