aboutsummaryrefslogtreecommitdiff
path: root/simon
diff options
context:
space:
mode:
authorMax Horn2004-06-25 22:12:57 +0000
committerMax Horn2004-06-25 22:12:57 +0000
commit7a8d469c666f162570f633ec465798e1e5720eef (patch)
tree1b124b178c1526de284989e7dc4b5b0c0b68d63d /simon
parente5f90509a606819dec58b7642c9845373ae364d5 (diff)
downloadscummvm-rg350-7a8d469c666f162570f633ec465798e1e5720eef.tar.gz
scummvm-rg350-7a8d469c666f162570f633ec465798e1e5720eef.tar.bz2
scummvm-rg350-7a8d469c666f162570f633ec465798e1e5720eef.zip
Use auto_ptr to avoid leaks
svn-id: r14057
Diffstat (limited to 'simon')
-rw-r--r--simon/simon.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/simon/simon.cpp b/simon/simon.cpp
index b2584b496c..9d30c14b47 100644
--- a/simon/simon.cpp
+++ b/simon/simon.cpp
@@ -42,6 +42,8 @@
#include <errno.h>
#include <time.h>
+#include <memory>
+
#ifdef __PALM_OS__
#include "globals.h"
#endif
@@ -2623,7 +2625,8 @@ int SimonEngine::count_savegames() {
uint i = 1;
bool marks[256];
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
char *prefix = gen_savename(999);
prefix[strlen(prefix)-3] = '\0';
mgr->list_savefiles(prefix, getSavePath(), marks, 256);
@@ -2637,7 +2640,6 @@ int SimonEngine::count_savegames() {
} else
break;
}
- delete mgr;
return i;
}
@@ -2651,7 +2653,8 @@ int SimonEngine::display_savegame_list(int curpos, bool load, char *dst) {
slot = curpos;
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
while (curpos + 6 > slot) {
if(!(in = mgr->open_savefile(gen_savename(slot), getSavePath(), false)))
@@ -2685,8 +2688,6 @@ int SimonEngine::display_savegame_list(int curpos, bool load, char *dst) {
}
}
- delete mgr;
-
return slot - curpos;
}
@@ -4806,11 +4807,11 @@ bool SimonEngine::save_game(uint slot, char *caption) {
errno = 0;
#endif
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
f = mgr->open_savefile(gen_savename(slot), getSavePath(), true);
if (f == NULL) {
- delete mgr;
_lock_word &= ~0x100;
return false;
}
@@ -4881,7 +4882,6 @@ bool SimonEngine::save_game(uint slot, char *caption) {
f->writeUint16BE(_bit_array[i]);
delete f;
- delete mgr;
_lock_word &= ~0x100;
@@ -4892,9 +4892,9 @@ char *SimonEngine::gen_savename(int slot) {
static char buf[15];
if (_game & GF_SIMON2) {
- sprintf(buf, "simon2.%.3d", slot);
+ sprintf(buf, "simon2.%.3d", slot);
} else {
- sprintf(buf, "simon1.%.3d", slot);
+ sprintf(buf, "simon1.%.3d", slot);
}
return buf;
}
@@ -4910,11 +4910,11 @@ bool SimonEngine::load_game(uint slot) {
errno = 0;
#endif
- SaveFileManager *mgr = _system->get_savefile_manager();
+ const std::auto_ptr<SaveFileManager> mgr(_system->get_savefile_manager());
+
f = mgr->open_savefile(gen_savename(slot), getSavePath(), false);
if (f == NULL) {
- delete mgr;
_lock_word &= ~0x100;
return false;
}
@@ -4925,7 +4925,6 @@ bool SimonEngine::load_game(uint slot) {
if (f->readUint32BE() != 0xFFFFFFFF || num != _itemarray_inited - 1) {
delete f;
- delete mgr;
_lock_word &= ~0x100;
return false;
}
@@ -5003,7 +5002,6 @@ bool SimonEngine::load_game(uint slot) {
_bit_array[i] = f->readUint16BE();
delete f;
- delete mgr;
_no_parent_notify = false;