diff options
author | Filippos Karapetis | 2015-12-07 11:00:54 +0200 |
---|---|---|
committer | Willem Jan Palenstijn | 2015-12-23 21:33:53 +0100 |
commit | 0e886461d0c60f1d3f1f790da8755e35ed2883d3 (patch) | |
tree | a8007732f02e4751b031a5c18d826c41f7f0fe70 /engines | |
parent | 156ad539ffe30c9a09952f7b97e285a5a5096b0d (diff) | |
download | scummvm-rg350-0e886461d0c60f1d3f1f790da8755e35ed2883d3.tar.gz scummvm-rg350-0e886461d0c60f1d3f1f790da8755e35ed2883d3.tar.bz2 scummvm-rg350-0e886461d0c60f1d3f1f790da8755e35ed2883d3.zip |
LAB: Replace some uses of malloc() with new
Diffstat (limited to 'engines')
-rw-r--r-- | engines/lab/engine.cpp | 8 | ||||
-rw-r--r-- | engines/lab/interface.cpp | 2 | ||||
-rw-r--r-- | engines/lab/lab.cpp | 2 | ||||
-rw-r--r-- | engines/lab/labsets.cpp | 5 | ||||
-rw-r--r-- | engines/lab/music.cpp | 2 | ||||
-rw-r--r-- | engines/lab/resource.cpp | 15 |
6 files changed, 18 insertions, 16 deletions
diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp index 53e61c4aa6..ee61e2ff26 100644 --- a/engines/lab/engine.cpp +++ b/engines/lab/engine.cpp @@ -526,20 +526,20 @@ void LabEngine::mainGameLoop() { delete _roomsFound; if (_rooms) { - free(_rooms); + delete[] _rooms; _rooms = nullptr; } if (_inventory) { for (int i = 1; i <= _numInv; i++) { if (_inventory[i]._name) - free(_inventory[i]._name); + delete _inventory[i]._name; if (_inventory[i]._bitmapName) - free(_inventory[i]._bitmapName); + delete _inventory[i]._bitmapName; } - free(_inventory); + delete[] _inventory; } } diff --git a/engines/lab/interface.cpp b/engines/lab/interface.cpp index a044fda849..9ab570ad02 100644 --- a/engines/lab/interface.cpp +++ b/engines/lab/interface.cpp @@ -63,7 +63,7 @@ Gadget *createButton(uint16 x, uint16 y, uint16 id, uint16 key, Image *im, Image void freeButtonList(GadgetList *gadgetList) { for (GadgetList::iterator gadget = gadgetList->begin(); gadget != gadgetList->end(); ++gadget) { - free(*gadget); + delete *gadget; } gadgetList->clear(); diff --git a/engines/lab/lab.cpp b/engines/lab/lab.cpp index 02abf800f5..3def00339c 100644 --- a/engines/lab/lab.cpp +++ b/engines/lab/lab.cpp @@ -129,7 +129,7 @@ LabEngine::~LabEngine() { delete _music; delete _anim; delete _graphics; - free(_rooms); + delete[] _rooms; for (int i = 0; i < 16; i++) delete _tiles[i]; diff --git a/engines/lab/labsets.cpp b/engines/lab/labsets.cpp index 259858763e..f09f669b7f 100644 --- a/engines/lab/labsets.cpp +++ b/engines/lab/labsets.cpp @@ -37,12 +37,13 @@ namespace Lab { LargeSet::LargeSet(uint16 last, LabEngine *vm) : _vm(vm) { last = (((last + 15) >> 4) << 4); - _array = (uint16 *)calloc(last >> 3, 2); + _array = new uint16[last >> 3]; + memset(_array, 0, last >> 3); _lastElement = last; } LargeSet::~LargeSet() { - free(_array); + delete[] _array; } bool LargeSet::in(uint16 element) { diff --git a/engines/lab/music.cpp b/engines/lab/music.cpp index 1260fd81fe..8fd88ff3e6 100644 --- a/engines/lab/music.cpp +++ b/engines/lab/music.cpp @@ -356,6 +356,8 @@ void Music::readSound(bool waitTillFinished, Common::File *file) { uint16 sampleRate = file->readUint16LE(); file->skip(2); + // NOTE: We need to use malloc(), cause this will be freed with free() + // by the music code byte *soundData = (byte *)malloc(soundSize); file->read(soundData, soundSize); playSoundEffect(sampleRate, soundSize, soundData); diff --git a/engines/lab/resource.cpp b/engines/lab/resource.cpp index f99ab82a53..de1e9dc714 100644 --- a/engines/lab/resource.cpp +++ b/engines/lab/resource.cpp @@ -90,7 +90,7 @@ bool Resource::readRoomData(const char *fileName) { _vm->_manyRooms = dataFile->readUint16LE(); _vm->_highestCondition = dataFile->readUint16LE(); - _vm->_rooms = (RoomData *)malloc((_vm->_manyRooms + 1) * sizeof(RoomData)); + _vm->_rooms = new RoomData[_vm->_manyRooms + 1]; memset(_vm->_rooms, 0, (_vm->_manyRooms + 1) * sizeof(RoomData)); for (uint16 i = 1; i <= _vm->_manyRooms; i++) { @@ -116,7 +116,7 @@ InventoryData *Resource::readInventory(const char *fileName) { Common::File *dataFile = openDataFile(fileName, MKTAG('I', 'N', 'V', '1')); _vm->_numInv = dataFile->readUint16LE(); - InventoryData *inventory = (InventoryData *)malloc((_vm->_numInv + 1) * sizeof(InventoryData)); + InventoryData *inventory = new InventoryData[_vm->_numInv + 1]; for (uint16 i = 1; i <= _vm->_numInv; i++) { inventory[i]._many = dataFile->readUint16LE(); @@ -195,7 +195,7 @@ char *Resource::readString(Common::File *file) { byte size = file->readByte(); if (!size) return NULL; - char *str = (char *)malloc(size); + char *str = new char[size]; char *c = str; for (int i = 0; i < size; i++) { *c = file->readByte(); @@ -209,8 +209,7 @@ char *Resource::readString(Common::File *file) { int16 *Resource::readConditions(Common::File *file) { int16 i = 0, cond; - //int16 *list = new int16[25]; - int16 *list = (int16 *)malloc(25 * 2); + int16 *list = new int16[25]; memset(list, 0, 25 * 2); do { @@ -254,7 +253,7 @@ Action *Resource::readAction(Common::File *file) { c = file->readByte(); if (c == 1) { - action = (Action *)malloc(sizeof(Action)); + action = new Action(); if (!head) head = action; if (prev) @@ -293,7 +292,7 @@ CloseData *Resource::readCloseUps(uint16 depth, Common::File *file) { c = file->readByte(); if (c != '\0') { - closeup = (CloseData *)malloc(sizeof(CloseData)); + closeup = new CloseData(); if (!head) head = closeup; if (prev) @@ -325,7 +324,7 @@ ViewData *Resource::readView(Common::File *file) { c = file->readByte(); if (c == 1) { - view = (ViewData *)malloc(sizeof(ViewData)); + view = new ViewData(); if (!head) head = view; if (prev) |