From 28259f914c06100ea58ed31680d7b5deb80ead5f Mon Sep 17 00:00:00 2001 From: cc9cii Date: Wed, 11 Mar 2015 10:49:21 +1100 Subject: [PATCH] Remove potential memory leak. --- apps/opencs/model/world/record.hpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/opencs/model/world/record.hpp b/apps/opencs/model/world/record.hpp index a0ddd8bc8..1cf14a8f9 100644 --- a/apps/opencs/model/world/record.hpp +++ b/apps/opencs/model/world/record.hpp @@ -40,6 +40,13 @@ namespace CSMWorld ESXRecordT mBase; ESXRecordT mModified; + Record() = default; + Record(const Record&) = default; + Record& operator= (const Record&) = default; + + Record(State state, + const ESXRecordT *base = 0, const ESXRecordT *modified = 0); + virtual RecordBase *clone() const; virtual RecordBase *modifiedCopy() const; @@ -62,14 +69,22 @@ namespace CSMWorld ///< Merge modified into base. }; + template + Record::Record(State state, const ESXRecordT *base, const ESXRecordT *modified) + { + if(base) + mBase = *base; + + if(modified) + mModified = *modified; + + this->mState = state; + } + template RecordBase *Record::modifiedCopy() const { - Record *record = new Record (*this); - record->mModified = record->mBase; - record->mBase = ESXRecordT(); - record->mState = RecordBase::State_ModifiedOnly; - return record; + return new Record (State_ModifiedOnly, 0, &(this->get())); } template