aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2009-02-27 19:38:20 +0000
committerWillem Jan Palenstijn2009-02-27 19:38:20 +0000
commitfb552121d234ab200caf8857f007df57085ca7ec (patch)
treede52e69df49a35c9d5730ef1253e975aa9cfed57
parentede680738b5594d8400bb3c60f284d6c1020cdda (diff)
downloadscummvm-rg350-fb552121d234ab200caf8857f007df57085ca7ec.tar.gz
scummvm-rg350-fb552121d234ab200caf8857f007df57085ca7ec.tar.bz2
scummvm-rg350-fb552121d234ab200caf8857f007df57085ca7ec.zip
fix warnings and memleaks in savegame.cfsml
svn-id: r38933
-rw-r--r--engines/sci/engine/savegame.cfsml4
-rw-r--r--engines/sci/engine/savegame.cpp4
-rw-r--r--engines/sci/engine/seg_manager.cpp7
-rw-r--r--engines/sci/engine/state.h4
-rw-r--r--engines/sci/engine/vm.h2
5 files changed, 12 insertions, 9 deletions
diff --git a/engines/sci/engine/savegame.cfsml b/engines/sci/engine/savegame.cfsml
index 3317abf5a0..e59467ed60 100644
--- a/engines/sci/engine/savegame.cfsml
+++ b/engines/sci/engine/savegame.cfsml
@@ -737,9 +737,9 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename
SavegameMetadata *meta = new SavegameMetadata;
meta->savegame_version = FREESCI_CURRENT_SAVEGAME_VERSION;
- meta->savegame_name = savename;
+ meta->savegame_name = sci_strdup(savename);
meta->version = s->version;
- meta->game_version = s->game_version;
+ meta->game_version = sci_strdup(s->game_version);
meta->savegame_date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
meta->savegame_time = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF);
fprintf(stderr, "date/time: %d %d\n", meta->savegame_date, meta->savegame_time);
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 0ea6cbbe8b..da8389167f 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -4791,9 +4791,9 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename
SavegameMetadata *meta = new SavegameMetadata;
meta->savegame_version = FREESCI_CURRENT_SAVEGAME_VERSION;
- meta->savegame_name = savename;
+ meta->savegame_name = sci_strdup(savename);
meta->version = s->version;
- meta->game_version = s->game_version;
+ meta->game_version = sci_strdup(s->game_version);
meta->savegame_date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
meta->savegame_time = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF);
fprintf(stderr, "date/time: %d %d\n", meta->savegame_date, meta->savegame_time);
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 9811505adb..977e3f808d 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -252,8 +252,9 @@ int SegManager::deallocate(int seg, bool recursive) {
break;
case MEM_OBJ_DYNMEM:
- if (mobj->data.dynmem.buf)
- free(mobj->data.dynmem.buf);
+ free(mobj->data.dynmem.description);
+ mobj->data.dynmem.description = NULL;
+ free(mobj->data.dynmem.buf);
mobj->data.dynmem.buf = NULL;
break;
case MEM_OBJ_SYS_STRINGS:
@@ -1398,7 +1399,7 @@ unsigned char *SegManager::allocDynmem(int size, const char *descr, reg_t *addr)
else
mobj->data.dynmem.buf = (byte*) sci_malloc(size);
- mobj->data.dynmem.description = descr;
+ mobj->data.dynmem.description = sci_strdup(descr);
return (unsigned char *)(mobj->data.dynmem.buf);
}
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index 8d49b0b184..173059f042 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -86,7 +86,9 @@ struct drawn_pic_t {
// Savegame metadata
struct SavegameMetadata {
- const char *savegame_name;
+ SavegameMetadata() : savegame_name(0), game_version(0) { }
+ ~SavegameMetadata() { free(savegame_name); free(game_version); }
+ char *savegame_name;
int savegame_version;
char *game_version;
sci_version_t version;
diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h
index bd71dc6438..608f9b7550 100644
--- a/engines/sci/engine/vm.h
+++ b/engines/sci/engine/vm.h
@@ -267,7 +267,7 @@ DECLARE_HEAPENTRY(hunk)
struct dynmem_t {
int size;
- const char *description;
+ char *description;
byte *buf;
}; /* Free-style memory */