Fixed a bunch of cppcheck warnings. Mostly about checking if a pointer is null

before freeing it, which isn't necessary.

svn-id: r46941
This commit is contained in:
Torbjörn Andersson 2010-01-03 19:37:43 +00:00
parent 910ffb53a0
commit 72eb9ec9ea
62 changed files with 117 additions and 210 deletions

@ -36,7 +36,7 @@ namespace Common {
Keymap::Keymap(const Keymap& km) : _actions(km._actions), _keymap(), _configDomain(0) {
List<Action*>::iterator it;
for (it = _actions.begin(); it != _actions.end(); it++) {
for (it = _actions.begin(); it != _actions.end(); ++it) {
const HardwareKey *hwKey = (*it)->getMappedKey();
if (hwKey) {
@ -48,7 +48,7 @@ Keymap::Keymap(const Keymap& km) : _actions(km._actions), _keymap(), _configDoma
Keymap::~Keymap() {
List<Action*>::iterator it;
for (it = _actions.begin(); it != _actions.end(); it++)
for (it = _actions.begin(); it != _actions.end(); ++it)
delete *it;
}
@ -87,7 +87,7 @@ Action *Keymap::getAction(const char *id) {
Action *Keymap::findAction(const char *id) {
List<Action*>::iterator it;
for (it = _actions.begin(); it != _actions.end(); it++) {
for (it = _actions.begin(); it != _actions.end(); ++it) {
if (strncmp((*it)->id, id, ACTION_ID_SIZE) == 0)
return *it;
}
@ -97,7 +97,7 @@ Action *Keymap::findAction(const char *id) {
const Action *Keymap::findAction(const char *id) const {
List<Action*>::const_iterator it;
for (it = _actions.begin(); it != _actions.end(); it++) {
for (it = _actions.begin(); it != _actions.end(); ++it) {
if (strncmp((*it)->id, id, ACTION_ID_SIZE) == 0)
return *it;
}
@ -127,7 +127,7 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) {
ConfigManager::Domain::iterator it;
String prefix = KEYMAP_KEY_PREFIX + _name + "_";
for (it = _configDomain->begin(); it != _configDomain->end(); it++) {
for (it = _configDomain->begin(); it != _configDomain->end(); ++it) {
const String& key = it->_key;
if (!key.hasPrefix(prefix.c_str()))
@ -164,7 +164,7 @@ void Keymap::saveMappings() {
List<Action*>::const_iterator it;
String prefix = KEYMAP_KEY_PREFIX + _name + "_";
for (it = _actions.begin(); it != _actions.end(); it++) {
for (it = _actions.begin(); it != _actions.end(); ++it) {
uint actIdLen = strlen((*it)->id);
actIdLen = (actIdLen > ACTION_ID_SIZE) ? ACTION_ID_SIZE : actIdLen;
@ -186,7 +186,7 @@ bool Keymap::isComplete(const HardwareKeySet *hwKeys) {
bool allMapped = true;
uint numberMapped = 0;
for (it = _actions.begin(); it != _actions.end(); it++) {
for (it = _actions.begin(); it != _actions.end(); ++it) {
if ((*it)->getMappedKey()) {
numberMapped++;
} else {

@ -41,7 +41,7 @@ void Keymapper::Domain::addKeymap(Keymap *map) {
}
void Keymapper::Domain::deleteAllKeyMaps() {
for (iterator it = begin(); it != end(); it++)
for (iterator it = begin(); it != end(); ++it)
delete it->_value;
clear();

@ -94,7 +94,7 @@ void RemapDialog::open() {
if (_globalKeymaps) {
if (divider)
_kmPopUp->appendEntry("");
for (it = _globalKeymaps->begin(); it != _globalKeymaps->end(); it++) {
for (it = _globalKeymaps->begin(); it != _globalKeymaps->end(); ++it) {
_kmPopUp->appendEntry(it->_value->getName() + " (Global)", idx);
_keymapTable[idx++] = it->_value;
}
@ -104,7 +104,7 @@ void RemapDialog::open() {
if (_gameKeymaps) {
if (divider)
_kmPopUp->appendEntry("");
for (it = _gameKeymaps->begin(); it != _gameKeymaps->end(); it++) {
for (it = _gameKeymaps->begin(); it != _gameKeymaps->end(); ++it) {
_kmPopUp->appendEntry(it->_value->getName() + " (Game)", idx);
_keymapTable[idx++] = it->_value;
}
@ -317,7 +317,7 @@ void RemapDialog::loadKeymap() {
List<Action*>::iterator it;
for (it = km->getActions().begin(); it != km->getActions().end(); it++) {
for (it = km->getActions().begin(); it != km->getActions().end(); ++it) {
ActionInfo info = {*it, false, (*it)->description};
_currentActions.push_back(info);

@ -320,13 +320,12 @@ int MidiDriver_TIMIDITY::connect_to_server(const char* hostname, unsigned short
char *MidiDriver_TIMIDITY::timidity_ctl_command(const char *fmt, ...) {
/* XXX: I don't like this static buffer!!! */
static char buff[BUFSIZ];
int status, len;
va_list ap;
if (fmt != NULL) {
/* if argumends are present, write them to control connection */
va_start(ap, fmt);
len = vsnprintf(buff, BUFSIZ-1, fmt, ap); /* leave one byte for \n */
int len = vsnprintf(buff, BUFSIZ-1, fmt, ap); /* leave one byte for \n */
va_end(ap);
/* add newline if needed */
@ -345,7 +344,7 @@ char *MidiDriver_TIMIDITY::timidity_ctl_command(const char *fmt, ...) {
}
/* report errors from server */
status = atoi(buff);
int status = atoi(buff);
if (400 <= status && status <= 499) { /* Error of data stream */
warning("TiMidity: error from server: %s", buff);
continue;

@ -72,8 +72,7 @@ void EventDispatcher::dispatch() {
}
void EventDispatcher::registerMapper(EventMapper *mapper) {
if (_mapper)
delete _mapper;
delete _mapper;
_mapper = mapper;
}

@ -203,12 +203,8 @@ void EventRecorder::deinit() {
g_system->unlockMutex(_timeMutex);
g_system->unlockMutex(_recorderMutex);
if (_playbackFile != NULL) {
delete _playbackFile;
}
if (_playbackTimeFile != NULL) {
delete _playbackTimeFile;
}
delete _playbackFile;
delete _playbackTimeFile;
if (_recordFile != NULL) {
_recordFile->finalize();

@ -894,8 +894,7 @@ AGOSEngine::~AGOSEngine() {
delete _gameFile;
_midi.close();
if (_driver)
delete _driver;
delete _driver;
AudioCD.stop();

@ -194,7 +194,7 @@ SaveStateList AgosMetaEngine::listSaves(const char *target) const {
sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)
SaveStateList saveList;
for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++) {
for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
// Obtain the last 3 digits of the filename, since they correspond to the save slot
int slotNum = atoi(file->c_str() + file->size() - 3);

@ -49,7 +49,7 @@ int AGOSEngine::countSaveGames() {
memset(marks, false, 256 * sizeof(bool)); //assume no savegames for this title
filenames = _saveFileMan->listSavefiles(prefix);
for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){
for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file){
//Obtain the last 3 digits of the filename, since they correspond to the save slot
slot[0] = file->c_str()[file->size()-3];
slot[1] = file->c_str()[file->size()-2];

@ -40,7 +40,7 @@ Common::List<overlay> overlayList;
/*! \brief Resets all elements in the object table. */
void resetObjectTable() {
for (Common::Array<ObjectStruct>::iterator it = objectTable.begin(); it != objectTable.end(); it++) {
for (Common::Array<ObjectStruct>::iterator it = objectTable.begin(); it != objectTable.end(); ++it) {
it->clear();
}
}

@ -262,7 +262,7 @@ SaveStateList CruiseMetaEngine::listSaves(const char *target) const {
Cruise::CruiseSavegameHeader header;
Cruise::readSavegameHeader(in, header);
saveList.push_back(SaveStateDescriptor(slotNum, header.saveName));
if (header.thumbnail) delete header.thumbnail;
delete header.thumbnail;
delete in;
}
}

@ -828,7 +828,7 @@ Common::Error loadSavegameData(int saveGameIdx) {
// Skip over the savegame header
CruiseSavegameHeader header;
readSavegameHeader(f, header);
if (header.thumbnail) delete header.thumbnail;
delete header.thumbnail;
// Synchronise the remaining data of the savegame
Common::Serializer s(f, NULL);

@ -238,10 +238,7 @@ SaveStateDescriptor GroovieMetaEngine::querySaveMetaInfos(const char *target, in
SaveStateDescriptor desc;
Common::InSaveFile *savefile = SaveLoad::openForLoading(target, slot, &desc);
if (savefile) {
// Loaded correctly
delete savefile;
}
delete savefile;
return desc;
}

@ -2202,6 +2202,7 @@ int LoLEngine::olol_restoreMagicShroud(EMCState *script) {
WSAMovie_v2 *mov = new WSAMovie_v2(this);
mov->open("DARKLITE.WSA", 2, 0);
if (!mov->opened()) {
delete mov;
warning("LoLEngine::olol_restoreMagicShroud: Could not open file: \"DARKLITE.WSA\"");
return 1;
}

@ -213,8 +213,7 @@ AnimationSequence::AnimationSequence(uint16 screenId, Palette &palette, bool fa
}
AnimationSequence::~AnimationSequence() {
if (_lineRefs != NULL)
delete _lineRefs;
delete _lineRefs;
delete _decodedData;
// Renable GMM saving/loading now that the animation is done

@ -49,7 +49,7 @@ Disk::Disk() {
}
Disk::~Disk() {
if (_fileHandle) delete _fileHandle;
delete _fileHandle;
int_disk = NULL;
}

@ -49,9 +49,8 @@ FightsManager::FightsManager() : _rnd(LureEngine::getReference().rnd()) {
}
FightsManager::~FightsManager() {
if (_fightData != NULL)
// Release the fight data
delete _fightData;
// Release the fight data
delete _fightData;
}
FightsManager &FightsManager::getReference() {

@ -199,7 +199,7 @@ Hotspot::Hotspot(): _pathFinder(NULL) {
}
Hotspot::~Hotspot() {
if (_frames) delete _frames;
delete _frames;
}
void Hotspot::setAnimation(uint16 newAnimId) {

@ -131,8 +131,13 @@ bool Introduction::show() {
anim = new AnimationSequence(curr_anim->resourceId,
isEGA ? EgaPalette : coll.getPalette(curr_anim->paletteIndex), fadeIn,
(curr_anim->resourceId == 0x44) ? 4 : 7);
if (curr_anim->initialPause != 0)
if (interruptableDelay(curr_anim->initialPause * 1000 / 50)) return true;
if (curr_anim->initialPause != 0) {
if (interruptableDelay(curr_anim->initialPause * 1000 / 50)) {
delete anim;
return true;
}
}
result = false;
switch (anim->show()) {

@ -175,7 +175,7 @@ uint8 Menu::execute() {
system.delayMillis(10);
}
if (_surfaceMenu) delete _surfaceMenu;
delete _surfaceMenu;
// Deselect the currently selected menu header
if (_selectedMenu)

@ -150,7 +150,7 @@ bool RoomExitData::insideRect(int16 xp, int16 yp) {
RoomExitData *RoomExitList::checkExits(int16 xp, int16 yp) {
iterator i;
for (i = begin(); i != end(); i++) {
for (i = begin(); i != end(); ++i) {
RoomExitData *rec = (*i).get();
if (rec->insideRect(xp, yp)) {
return rec;

@ -116,10 +116,9 @@ Room::Room(): _screen(Screen::getReference()) {
Room::~Room() {
for (int layerNum = 0; layerNum < _numLayers; ++layerNum)
if (_layers[layerNum])
delete _layers[layerNum];
delete _layers[layerNum];
if (_talkDialog) delete _talkDialog;
delete _talkDialog;
int_room = NULL;
}

@ -82,8 +82,7 @@ SoundManager::~SoundManager() {
g_system->unlockMutex(_soundMutex);
delete _descs;
if (_soundData)
delete _soundData;
delete _soundData;
if (_driver) {
_driver->close();
@ -641,8 +640,7 @@ MidiMusic::~MidiMusic() {
_parser->unloadMusic();
delete _parser;
this->close();
if (_decompressedSound != NULL)
delete _decompressedSound;
delete _decompressedSound;
}
void MidiMusic::setVolume(int volume) {

@ -95,8 +95,7 @@ void Actor::unloadWalkers() {
continue; // walker sprite 6 is unused
SpriteAsset *tempSprite = _walkerSprites[i];
_walkerSprites.remove_at(i);
if (tempSprite)
delete tempSprite;
delete tempSprite;
}
}

@ -186,8 +186,7 @@ Mouse::Mouse(M4Engine *vm) : _vm(vm) {
}
Mouse::~Mouse() {
if (_cursorSprites)
delete _cursorSprites;
delete _cursorSprites;
}
bool Mouse::init(const char *seriesName, RGB8 *palette) {

@ -397,7 +397,7 @@ const char *Globals::loadMessage(uint index) {
if (buffer[i] == '\0') buffer[i] = '\n';
_vm->res()->toss("messages.dat");
delete compData;
delete[] compData;
return (char*)buffer;
}

@ -90,8 +90,7 @@ MenuObject::MenuObject(DialogView *owner, int objectId, int xs, int ys, int widt
}
MenuObject::~MenuObject() {
if (_background)
delete _background;
delete _background;
}
void MenuObject::onExecute() {

@ -433,10 +433,8 @@ OrionMenuView::~OrionMenuView() {
delete *i;
_menuObjects.clear();
if (_saveNames)
delete _saveNames;
if (_savegameThumbnail)
delete _savegameThumbnail;
delete _saveNames;
delete _savegameThumbnail;
}
bool OrionMenuView::loadSprites(const char *seriesName) {

@ -75,12 +75,9 @@ TextviewView::TextviewView(M4Engine *vm):
TextviewView::~TextviewView() {
if (_script)
_vm->res()->toss(_resourceName);
if (_spareScreen)
delete _spareScreen;
if (_bgCurrent)
delete _bgCurrent;
if (_bgSpare)
delete _bgSpare;
delete _spareScreen;
delete _bgCurrent;
delete _bgSpare;
}
void TextviewView::reset() {

@ -74,8 +74,7 @@ RexMainMenuView::RexMainMenuView(M4Engine *vm):
}
RexMainMenuView::~RexMainMenuView() {
if (_menuItem)
delete _menuItem;
delete _menuItem;
_vm->_palette->deleteRange(_bgPalData);
@ -121,8 +120,7 @@ bool RexMainMenuView::onEvent(M4EventType eventType, int32 param, int x, int y,
// Goodness knows why, but Rex has a key to restart the menuitem animations
// Delete the current menu items
if (_menuItem)
delete _menuItem;
delete _menuItem;
_vm->_palette->deleteRange(_bgPalData);
delete _bgPalData;

@ -47,9 +47,7 @@ MidiPlayer::~MidiPlayer() {
stopMusic();
close();
delete _parser;
if (_midiData)
free(_midiData);
free(_midiData);
}
void MidiPlayer::setVolume(int volume) {

@ -73,21 +73,13 @@ Scene::~Scene() {
delete _backgroundSurface;
delete _codeSurface;
if (_sceneSprites)
delete _sceneSprites;
delete _sceneSprites;
// _vm->_palette->deleteAllRanges();
if (_palData)
delete _palData;
if (_interfacePal)
delete _interfacePal;
if (_inverseColorTable)
delete[] _inverseColorTable;
delete _palData;
delete _interfacePal;
delete[] _inverseColorTable;
}
void Scene::loadScene(int sceneNumber) {
@ -284,8 +276,7 @@ void Scene::loadSceneInverseColorTable(int sceneNumber) {
if (_vm->isM4()) {
sprintf(filename, "%i.ipl", sceneNumber);
iplS = _vm->res()->openFile(filename);
if (_inverseColorTable)
delete[] _inverseColorTable;
delete[] _inverseColorTable;
_inverseColorTable = new byte[iplS->size()];
iplS->read(_inverseColorTable, iplS->size());
_vm->res()->toss(filename);

@ -101,8 +101,7 @@ StringTable::StringTable() : _stringsData(NULL) {
}
StringTable::~StringTable() {
if (_stringsData)
delete[] _stringsData;
delete[] _stringsData;
}
void StringTable::load(Common::File *fd) {
@ -191,8 +190,7 @@ ScriptFunction::ScriptFunction(ScriptInterpreter *inter) : _inter(inter) {
}
ScriptFunction::~ScriptFunction() {
if (_code)
delete _code;
delete _code;
}
void ScriptFunction::load(Common::File *fd) {
@ -293,9 +291,7 @@ void ScriptInterpreter::open(const char *filename) {
}
void ScriptInterpreter::close() {
if (_scriptFile) {
delete _scriptFile;
}
delete _scriptFile;
}
void ScriptInterpreter::initScriptKernel() {

@ -180,7 +180,7 @@ Sequence *WoodScript::createSequence(Machine *machine, int32 sequenceHash) {
void WoodScript::runSequencePrograms() {
// A lot TODO
for (Common::Array<Sequence*>::iterator it = _sequences.begin(); it != _sequences.end(); it++) {
for (Common::Array<Sequence*>::iterator it = _sequences.begin(); it != _sequences.end(); ++it) {
Sequence *sequence = *it;
if (sequence->isActive()) {
sequence->runProgram();

@ -255,8 +255,7 @@ GameDatabase::GameDatabase(MadeEngine *vm) : _vm(vm) {
}
GameDatabase::~GameDatabase() {
if (_gameState)
delete[] _gameState;
delete[] _gameState;
}
void GameDatabase::open(const char *filename) {
@ -388,8 +387,7 @@ GameDatabaseV2::GameDatabaseV2(MadeEngine *vm) : GameDatabase(vm), _gameText(NUL
}
GameDatabaseV2::~GameDatabaseV2() {
if (_gameText)
delete[] _gameText;
delete[] _gameText;
}
void GameDatabaseV2::load(Common::SeekableReadStream &sourceS) {

@ -115,9 +115,7 @@ bool PmvPlayer::play(const char *filename) {
// Only reallocate the frame data buffer if its size has changed
if (prevChunkSize != chunkSize || !frameData) {
if (frameData)
delete[] frameData;
delete[] frameData;
frameData = new byte[chunkSize];
}

@ -310,8 +310,7 @@ FontResource::FontResource() : _data(NULL), _size(0) {
}
FontResource::~FontResource() {
if (_data)
delete[] _data;
delete[] _data;
}
void FontResource::load(byte *source, int size) {
@ -362,8 +361,7 @@ GenericResource::GenericResource() : _data(NULL), _size(0) {
}
GenericResource::~GenericResource() {
if (_data)
delete[] _data;
delete[] _data;
}
void GenericResource::load(byte *source, int size) {

@ -47,7 +47,7 @@ bool MenuInputHelper::run() {
MenuInputHelper::~MenuInputHelper() {
StateMap::iterator b = _map.begin();
for ( ; b != _map.end(); b++) {
for ( ; b != _map.end(); ++b) {
delete b->_value;
}
_map.clear();

@ -66,11 +66,9 @@ void gfxr_free_pic(gfxr_pic_t *pic) {
pic->visual_map = NULL;
pic->priority_map = NULL;
pic->control_map = NULL;
if (pic->priorityTable)
free(pic->priorityTable);
free(pic->priorityTable);
pic->priorityTable = NULL;
if (pic->undithered_buffer)
free(pic->undithered_buffer);
free(pic->undithered_buffer);
pic->undithered_buffer = 0;
free(pic);
}

@ -44,10 +44,8 @@ SciGuiAnimate::SciGuiAnimate(EngineState *state, SciGuiGfx *gfx, SciGuiScreen *s
}
SciGuiAnimate::~SciGuiAnimate() {
if (_listData)
free(_listData);
if (_lastCastData)
free(_lastCastData);
free(_listData);
free(_lastCastData);
}
void SciGuiAnimate::init() {
@ -129,15 +127,13 @@ void SciGuiAnimate::makeSortedList(List *list) {
// Adjust list size, if needed
if ((_listData == NULL) || (_listCount < listCount)) {
if (_listData)
free(_listData);
free(_listData);
_listData = (GuiAnimateEntry *)malloc(listCount * sizeof(GuiAnimateEntry));
if (!_listData)
error("Could not allocate memory for _listData");
_listCount = listCount;
if (_lastCastData)
free(_lastCastData);
free(_lastCastData);
_lastCastData = (GuiAnimateEntry *)malloc(listCount * sizeof(GuiAnimateEntry));
if (!_lastCastData)
error("Could not allocate memory for _lastCastData");

@ -74,9 +74,7 @@ void SciGuiText::SetFont(GuiResourceId fontId) {
void SciGuiText::CodeSetFonts(int argc, reg_t *argv) {
int i;
if (_codeFonts) {
delete _codeFonts;
}
delete _codeFonts;
_codeFontsCount = argc;
_codeFonts = new GuiResourceId[argc];
for (i = 0; i < argc; i++) {
@ -87,9 +85,7 @@ void SciGuiText::CodeSetFonts(int argc, reg_t *argv) {
void SciGuiText::CodeSetColors(int argc, reg_t *argv) {
int i;
if (_codeColors) {
delete _codeColors;
}
delete _codeColors;
_codeColorsCount = argc;
_codeColors = new uint16[argc];
for (i = 0; i < argc; i++) {

@ -125,6 +125,7 @@ Palette *gfxr_read_pal1_amiga(Common::File &file) {
b2 = file.readByte();
if (b1 == EOF || b2 == EOF) {
delete retval;
error("Amiga palette file ends prematurely");
return NULL;
}

@ -332,8 +332,7 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) {
// play digital sample
if (track->digitalChannelNr != -1) {
byte *channelData = track->channels[track->digitalChannelNr].data;
if (pSnd->pStreamAud)
delete pSnd->pStreamAud;
delete pSnd->pStreamAud;
pSnd->pStreamAud = Audio::makeLinearInputStream(channelData, track->digitalSampleSize, track->digitalSampleRate,
Audio::Mixer::FLAG_UNSIGNED, 0, 0);
pSnd->soundType = Audio::Mixer::kSFXSoundType;

@ -238,9 +238,7 @@ void MidiDriver_Adlib::close() {
_mixer->stopHandle(_mixerSoundHandle);
delete _opl;
if (_rhythmKeyMap)
delete[] _rhythmKeyMap;
delete[] _rhythmKeyMap;
}
void MidiDriver_Adlib::setVolume(byte volume) {

@ -399,9 +399,7 @@ bool ScummDiskImage::generateIndex() {
extractIndex(&out);
if (_stream)
delete _stream;
delete _stream;
_stream = new Common::MemoryReadStream(_buf, bufsize);
return true;

@ -983,10 +983,8 @@ int Win32ResExtractor::convertIcons(byte *data, int datasize, byte **cursor, int
}
if (row != NULL)
free(row);
if (palette != NULL)
free(palette);
free(row);
free(palette);
if (image_data != NULL) {
free(image_data);
free(mask_data);
@ -995,10 +993,8 @@ int Win32ResExtractor::convertIcons(byte *data, int datasize, byte **cursor, int
local_cleanup:
if (row != NULL)
free(row);
if (palette != NULL)
free(palette);
free(row);
free(palette);
if (image_data != NULL) {
free(image_data);
free(mask_data);

@ -188,8 +188,7 @@ int Player::start_seq_sound(int sound, bool reset_vars) {
ptr = _se->findStartOfSound(sound);
if (ptr == NULL)
return -1;
if (_parser)
delete _parser;
delete _parser;
if (!memcmp(ptr, "RO", 2)) {
// Old style 'RO' resource

@ -273,8 +273,7 @@ void Instrument::nativeMT32(bool native) {
}
void Instrument::clear() {
if (_instrument)
delete _instrument;
delete _instrument;
_instrument = NULL;
_type = itNone;
}

@ -647,12 +647,8 @@ void SmushPlayer::handleTextResource(uint32 subType, int32 subSize, Common::Seek
error("SmushPlayer::handleTextResource. Not handled flags: %d", flags);
}
if (string != NULL) {
free (string);
}
if (string3 != NULL) {
free (string3);
}
free(string);
free(string3);
}
const char *SmushPlayer::getString(int id) {

@ -165,8 +165,7 @@ ControlStatus::ControlStatus(Text *skyText, OSystem *system, uint8 *scrBuf) {
}
ControlStatus::~ControlStatus() {
if (_textData)
free(_textData);
free(_textData);
delete _statusText;
}
@ -184,8 +183,7 @@ void ControlStatus::setToText(const char *newText) {
}
void ControlStatus::setToText(uint16 textNum) {
if (_textData)
free(_textData);
free(_textData);
DisplayedText disText = _skyText->displayText(textNum, NULL, true, STATUS_WIDTH, 255);
_textData = (DataFileHeader *)disText.textData;
_statusText->setSprite(_textData);
@ -330,16 +328,14 @@ void Control::initPanel() {
void Control::buttonControl(ConResource *pButton) {
char autoSave[] = "Restore Autosave";
if (pButton == NULL) {
if (_textSprite)
free(_textSprite);
free(_textSprite);
_textSprite = NULL;
_curButtonText = 0;
_text->setSprite(NULL);
return;
}
if (_curButtonText != pButton->_text) {
if (_textSprite)
free(_textSprite);
free(_textSprite);
_textSprite = NULL;
_curButtonText = pButton->_text;
if (pButton->_text) {
@ -647,8 +643,7 @@ bool Control::getYesNo(char *text) {
}
_mouseClicked = false;
_skyMouse->spriteMouse(MOUSE_NORMAL, 0, 0);
if (dlgTextDat)
free(dlgTextDat);
free(dlgTextDat);
delete dlgText;
return retVal;
}

@ -206,7 +206,7 @@ SaveStateList SkyMetaEngine::listSaves(const char *target) const {
saveList.insert_at(0, SaveStateDescriptor(0, "*AUTOSAVE*"));
// Prepare the list of savestates by looping over all matching savefiles
for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++) {
for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
// Extract the extension
Common::String ext = file->c_str() + file->size() - 3;
ext.toUppercase();

@ -743,8 +743,7 @@ bool Intro::nextPart(uint16 *&data) {
return true;
case LOADBG:
_mixer->stopID(SOUND_BG);
if (_bgBuf)
free(_bgBuf);
free(_bgBuf);
_bgBuf = _skyDisk->loadFile(*data++);
_bgSize = _skyDisk->_lastLoadedFileSize;
return true;

@ -40,16 +40,14 @@ MusicBase::MusicBase(Disk *pDisk) {
MusicBase::~MusicBase() {
stopMusic();
if (_musicData)
free(_musicData);
free(_musicData);
}
void MusicBase::loadSection(uint8 pSection) {
_mutex.lock();
if (_currentMusic)
stopMusicInternal();
if (_musicData)
free(_musicData);
free(_musicData);
_currentSection = pSection;
_musicData = _skyDisk->loadFile(_driverFileBase + FILES_PER_SECTION * pSection);

@ -93,10 +93,8 @@ Screen::Screen(OSystem *pSystem, Disk *pDisk, SkyCompact *skyCompact) {
Screen::~Screen() {
free(_gameGrid);
if (_currentScreen)
free(_currentScreen);
if (_scrollScreen)
free(_scrollScreen);
free(_currentScreen);
free(_scrollScreen);
}
void Screen::clearScreen() {
@ -151,8 +149,7 @@ void Screen::setPalette(uint16 fileNum) {
void Screen::showScreen(uint16 fileNum) {
// This is only used for static images in the floppy and cd intro
if (_currentScreen)
free(_currentScreen);
free(_currentScreen);
_currentScreen = _skyDisk->loadFile(fileNum);
// make sure the last 8 lines are forced to black.
memset(_currentScreen + GAME_SCREEN_HEIGHT * GAME_SCREEN_WIDTH, 0, (FULL_SCREEN_HEIGHT - GAME_SCREEN_HEIGHT) * GAME_SCREEN_WIDTH);

@ -1030,8 +1030,7 @@ Sound::Sound(Audio::Mixer *mixer, Disk *pDisk, uint8 pVolume) {
Sound::~Sound() {
_mixer->stopAll();
if (_soundData)
free(_soundData);
free(_soundData);
}
void Sound::playSound(uint32 id, byte *sound, uint32 size, Audio::SoundHandle *handle) {
@ -1049,8 +1048,7 @@ void Sound::loadSection(uint8 pSection) {
fnStopFx();
_mixer->stopAll();
if (_soundData)
free(_soundData);
free(_soundData);
_soundData = _skyDisk->loadFile(pSection * 4 + SOUND_FILE_BASE);
uint16 asmOfs;
if (SkyEngine::_systemVars.gameVersion == 109) {

@ -78,12 +78,9 @@ Text::~Text() {
SkyEngine::_itemList[i] = NULL;
}
if (_mainCharacterSet.addr)
free(_mainCharacterSet.addr);
if (_controlCharacterSet.addr)
free(_controlCharacterSet.addr);
if (_linkCharacterSet.addr)
free(_linkCharacterSet.addr);
free(_mainCharacterSet.addr);
free(_controlCharacterSet.addr);
free(_linkCharacterSet.addr);
}
void Text::fnSetFont(uint32 fontNr) {

@ -166,9 +166,7 @@ void ResMan::freeCluDescript() {
}
}
delete[] cluster->grp;
if (cluster->file != NULL)
delete cluster->file;
delete cluster->file;
}
delete[] _prj.clu;
}

@ -314,10 +314,8 @@ void Screen::newScreen(uint32 screen) {
Logic::_scriptVars[SCROLL_OFFSET_X] = 0;
Logic::_scriptVars[SCROLL_OFFSET_Y] = 0;
if (_screenBuf)
free(_screenBuf);
if (_screenGrid)
free(_screenGrid);
free(_screenBuf);
free(_screenGrid);
if (SwordEngine::isPsx())
flushPsxCache();
@ -554,11 +552,8 @@ void Screen::processImage(uint32 id) {
if (compact->o_type != TYPE_TEXT)
_resMan->resClose(compact->o_resource);
if (tonyBuf)
free(tonyBuf);
if (hifBuf)
free(hifBuf);
free(tonyBuf);
free(hifBuf);
}
void Screen::verticalMask(uint16 x, uint16 y, uint16 bWidth, uint16 bHeight) {

@ -52,8 +52,7 @@ static const byte command_lengths[8] = { 3, 3, 3, 3, 2, 2, 3, 0 };
static const byte special_lengths[16] = { 0, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 };
MidiParser_SMF::~MidiParser_SMF() {
if (_buffer)
free(_buffer);
free(_buffer);
}
void MidiParser_SMF::property(int prop, int value) {

@ -34,8 +34,7 @@ Infogrames::Instruments::Instruments() {
}
Infogrames::Instruments::~Instruments() {
if (_sampleData)
delete[] _sampleData;
delete[] _sampleData;
}
void Infogrames::Instruments::init() {
@ -104,8 +103,7 @@ bool Infogrames::Instruments::load(Common::SeekableReadStream &ins) {
}
void Infogrames::Instruments::unload() {
if (_sampleData)
delete[] _sampleData;
delete[] _sampleData;
init();
}
@ -142,8 +140,7 @@ Infogrames::Infogrames(Instruments &ins, bool stereo, int rate,
}
Infogrames::~Infogrames() {
if (_data)
delete[] _data;
delete[] _data;
}
void Infogrames::init() {

@ -248,8 +248,7 @@ MidiDriver_MT32::MidiDriver_MT32(Audio::Mixer *mixer) : MidiDriver_Emulated(mixe
}
MidiDriver_MT32::~MidiDriver_MT32() {
if (_synth != NULL)
delete _synth;
delete _synth;
}
int MidiDriver_MT32::open() {

@ -129,8 +129,7 @@ void Synth::printDebug(const char *fmt, ...) {
void Synth::initReverb(Bit8u newRevMode, Bit8u newRevTime, Bit8u newRevLevel) {
// FIXME:KG: I don't think it's necessary to recreate the reverbModel... Just set the parameters
if (reverbModel != NULL)
delete reverbModel;
delete reverbModel;
reverbModel = new revmodel();
switch (newRevMode) {