Skip to content

Commit cc70925

Browse files
committed
memento: Fix memory leak
The memento should be deleted after it is restored.
1 parent 0993acf commit cc70925

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Memento/Conceptual/main.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class Originator {
143143
void Restore(Memento *memento) {
144144
this->state_ = memento->state();
145145
std::cout << "Originator: My state has changed to: " << this->state_ << "\n";
146+
delete memento;
146147
}
147148
};
148149

@@ -229,4 +230,4 @@ int main() {
229230
std::srand(static_cast<unsigned int>(std::time(NULL)));
230231
ClientCode();
231232
return 0;
232-
}
233+
}

0 commit comments

Comments
 (0)