mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-25 05:34:27 +00:00
LAB: Replace some uses of malloc() with new
This commit is contained in:
parent
156ad539ff
commit
0e886461d0
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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];
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user