Merge pull request #4619 from ctrlaltdavid/memory-fixes

Memory fixes
This commit is contained in:
Clément Brisset 2015-04-09 18:51:02 +02:00
commit 59a5fac2f1
2 changed files with 5 additions and 5 deletions

View file

@ -27,9 +27,9 @@ Resource::Size Resource::Sysmem::allocateMemory(Byte** dataAllocated, Size size)
if (size > 0) { if (size > 0) {
// Try allocating as much as the required size + one block of memory // Try allocating as much as the required size + one block of memory
newSize = size; newSize = size;
(*dataAllocated) = new Byte[newSize]; try {
// Failed? (*dataAllocated) = new Byte[newSize];
if (!(*dataAllocated)) { } catch (const std::bad_alloc&) {
qWarning() << "Buffer::Sysmem::allocate() : Can't allocate a system memory buffer of " << newSize << "bytes. Fails to create the buffer Sysmem."; qWarning() << "Buffer::Sysmem::allocate() : Can't allocate a system memory buffer of " << newSize << "bytes. Fails to create the buffer Sysmem.";
return NOT_ALLOCATED; return NOT_ALLOCATED;
} }

View file

@ -1024,7 +1024,7 @@ int Octree::encodeTreeBitstream(OctreeElement* element,
roomForOctalCode = packetData->startSubTree(newCode); roomForOctalCode = packetData->startSubTree(newCode);
if (newCode) { if (newCode) {
delete newCode; delete[] newCode;
codeLength = numberOfThreeBitSectionsInCode(newCode); codeLength = numberOfThreeBitSectionsInCode(newCode);
} else { } else {
codeLength = 1; codeLength = 1;
@ -2064,7 +2064,7 @@ bool Octree::readJSONFromStream(unsigned long streamLength, QDataStream& inputSt
QVariant asVariant = asDocument.toVariant(); QVariant asVariant = asDocument.toVariant();
QVariantMap asMap = asVariant.toMap(); QVariantMap asMap = asVariant.toMap();
readFromMap(asMap); readFromMap(asMap);
delete rawData; delete[] rawData;
return true; return true;
} }