# HG changeset patch # User Jens Alfke # Date 1253813768 25200 # Node ID 715d6147ba3aac80bb4ba4a8ad34013c83b15327 # Parent 8e3ae153e2c9709e750d8f2b26561b1255301f3c * Fixed a bug in Ottoman: the parameterless constructor didn't initialize _file, leaving it garbage and leading to a crash if you deleted the object without saving. * This bug was being hidden by another bug in saveAs which didn't delete the old _file. * Also added a versionsChanged hook that subclasses can override. diff -r 8e3ae153e2c9 -r 715d6147ba3a include/Ottoman.h --- a/include/Ottoman.h Thu Sep 24 10:28:50 2009 -0700 +++ b/include/Ottoman.h Thu Sep 24 10:36:08 2009 -0700 @@ -79,6 +79,10 @@ bool scavenge (bool repair =false); ChunkIterator* chunkIterator() const; // for testing purposes + + protected: + /** Hook for subclassers: Called when new versions are added. */ + virtual void versionsChanged() { } private: Ottoman(const Ottoman&); // forbid copying/assignment diff -r 8e3ae153e2c9 -r 715d6147ba3a src/Ottoman.cpp --- a/src/Ottoman.cpp Thu Sep 24 10:28:50 2009 -0700 +++ b/src/Ottoman.cpp Thu Sep 24 10:36:08 2009 -0700 @@ -42,6 +42,7 @@ Ottoman::Ottoman() :_writeable(true), + _file(NULL), _filename(NULL), _lastVersion(NULL), _current( new OverlayDictionary(&Dictionary::kEmpty) ) @@ -96,6 +97,9 @@ delete _file; _file = curFile; } + + if (changed) + versionsChanged(); return changed; } @@ -196,11 +200,12 @@ if (!lastVersion) lastVersion = new VersionDictionary(dstFile); VersionDictionary *saved = lastVersion->_appendAndOpen(_current->overlay(), - dstFile, - _current->baseReplaced()); + dstFile, + _current->baseReplaced()); // (don't delete _lastVersion: saved->_previousVersion now points to it.) _lastVersion = saved; _current->revertTo(_lastVersion); + versionsChanged(); } bool Ottoman::save() { @@ -235,6 +240,7 @@ File *dstFile = _writeTo(dstFileName, overwriteAllowed); free(_filename); _filename = strdup(dstFileName); + delete _file; _file = dstFile; }