summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/files.cc
diff options
context:
space:
mode:
authorMatthew Cline <zelgadis@sourceforge.net>2009-11-25 04:38:58 -0800
committerMatthew Cline <zelgadis@sourceforge.net>2009-11-25 04:40:27 -0800
commitf86dbda480d70a0b34e4ec238a5917a206b4e402 (patch)
treea81fad3df845a19ecb81b79dac36005d8e210488 /crawl-ref/source/files.cc
parent64cedc8717dd2342af7dfce393e2aed02315f1ba (diff)
downloadcrawl-ref-f86dbda480d70a0b34e4ec238a5917a206b4e402.tar.gz
crawl-ref-f86dbda480d70a0b34e4ec238a5917a206b4e402.zip
Quiet save-and-quit Valgrind leak warnings
Split save_game() code which allocates std::string's on the stack out into seperate functions, so they'll go out of scope and be free'd before end() is called, thus getting rid of the spurious complaints Valgrind gives.
Diffstat (limited to 'crawl-ref/source/files.cc')
-rw-r--r--crawl-ref/source/files.cc37
1 files changed, 27 insertions, 10 deletions
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index 72227f94cd..896ea8f849 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -1561,13 +1561,10 @@ void _save_level(int level_saved, level_area_type old_ltype,
DO_CHMOD_PRIVATE(cha_fil.c_str());
}
-
-void save_game(bool leave_game, const char *farewellmsg)
+// Stack allocated std::string's go in seperate function, so Valgrind doesn't
+// complain.
+static void _save_game_base()
{
- unwind_bool saving_game(crawl_state.saving_game, true);
-
- SavefileCallback::pre_save();
-
/* Stashes */
std::string stashFile = get_savedir_filename(you.your_name, "", "st");
FILE *stashf = fopen(stashFile.c_str(), "wb");
@@ -1671,11 +1668,12 @@ void save_game(bool leave_game, const char *farewellmsg)
fclose(charf);
DO_CHMOD_PRIVATE(charFile.c_str());
+}
- // If just save, early out.
- if (!leave_game)
- return;
-
+// Stack allocated std::string's go in seperate function, so Valgrind doesn't
+// complain.
+static void _save_game_exit()
+{
// Must be exiting -- save level & goodbye!
if (!you.entering_level)
_save_level(you.your_level, you.level_type, you.where_are_you);
@@ -1708,6 +1706,25 @@ void save_game(bool leave_game, const char *farewellmsg)
delete _callback_list;
_callback_list = NULL;
}
+}
+
+void save_game(bool leave_game, const char *farewellmsg)
+{
+ unwind_bool saving_game(crawl_state.saving_game, true);
+
+ SavefileCallback::pre_save();
+
+ // Stack allocated std::string's go in seperate function,
+ // so Valgrind doesn't complain.
+ _save_game_base();
+
+ // If just save, early out.
+ if (!leave_game)
+ return;
+
+ // Stack allocated std::string's go in seperate function,
+ // so Valgrind doesn't complain.
+ _save_game_exit();
end(0, false, farewellmsg? "%s" : "See you soon, %s!",
farewellmsg? farewellmsg : you.your_name.c_str());