summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Fultz <jfultz@wolfram.com>2016-07-30 21:00:03 -0500
committerJohn Fultz <jfultz@wolfram.com>2016-07-30 21:00:03 -0500
commitbb2decabe18056b1aaaab29eebbc0f80e1f5e7ab (patch)
tree358f3a7d69118747d4bb3a493934f12b4ddc483c
parentd8e8ccf584be9bb6df91b4bba6541a7e32d25116 (diff)
Fix memory leak when reading game files.
-rw-r--r--quackleio/gcgio.cpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/quackleio/gcgio.cpp b/quackleio/gcgio.cpp
index 8f8112f..d28f347 100644
--- a/quackleio/gcgio.cpp
+++ b/quackleio/gcgio.cpp
@@ -32,20 +32,19 @@ GCGIO::GCGIO()
Quackle::Game *GCGIO::read(const QString &filename, int flags)
{
- QFile file(filename);
- Quackle::Game *ret = new Quackle::Game;
+ QFile file(filename);
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
- {
- UVcerr << "Could not open gcg " << QuackleIO::Util::qstringToString(filename) << endl;
- return ret;
- }
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ {
+ UVcerr << "Could not open gcg " << QuackleIO::Util::qstringToString(filename) << endl;
+ return new Quackle::Game;
+ }
- QTextStream in(&file);
- ret = read(in, flags);
- file.close();
+ QTextStream in(&file);
+ Quackle::Game *ret = read(in, flags);
+ file.close();
- return ret;
+ return ret;
}
Quackle::Game *GCGIO::read(QTextStream &stream, int flags)
@@ -343,7 +342,7 @@ void GCGIO::write(const Quackle::Game &game, QTextStream &stream)
const Quackle::PositionList::const_iterator end(game.history().end());
for (Quackle::PositionList::const_iterator it = game.history().begin(); it != end; ++it)
{
- Quackle::Move move = (*it).committedMove();
+ const Quackle::Move& move = (*it).committedMove();
move.setPrettyTiles((*it).board().prettyTilesOfMove(move, /* don't mark playthru */ false));
if (move.isAMove())