aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2015-12-19 12:42:22 +0200
committerWillem Jan Palenstijn2015-12-23 21:35:29 +0100
commit2a80c8066c613ea0eb75e9309e2981f3770102f1 (patch)
tree3f72c47f599a7760cfeb5ae39c8606cf98815eb1
parent406710bac6ecd0586ab450aea45e3e97e9012b85 (diff)
downloadscummvm-rg350-2a80c8066c613ea0eb75e9309e2981f3770102f1.tar.gz
scummvm-rg350-2a80c8066c613ea0eb75e9309e2981f3770102f1.tar.bz2
scummvm-rg350-2a80c8066c613ea0eb75e9309e2981f3770102f1.zip
LAB: Plug all the remaining resource-related memory leaks
-rw-r--r--engines/lab/resource.cpp71
-rw-r--r--engines/lab/resource.h4
2 files changed, 58 insertions, 17 deletions
diff --git a/engines/lab/resource.cpp b/engines/lab/resource.cpp
index 39b30238de..b673072482 100644
--- a/engines/lab/resource.cpp
+++ b/engines/lab/resource.cpp
@@ -158,22 +158,10 @@ bool Resource::readViews(uint16 roomNum) {
}
void Resource::freeViews(uint16 roomNum) {
- for (uint16 i = 0; i < 4; i++) {
- delete _vm->_rooms[roomNum]._view[i];
- _vm->_rooms[roomNum]._view[i] = nullptr;
- }
-
- if (_vm->_rooms[roomNum]._rules) {
- for (RuleList::iterator rule = _vm->_rooms[roomNum]._rules->begin(); rule != _vm->_rooms[roomNum]._rules->end(); ++rule) {
- delete (*rule)->_actionList;
- delete[](*rule)->_condition;
- delete *rule;
- *rule = nullptr;
- }
+ for (uint16 i = 0; i < 4; i++)
+ freeView(_vm->_rooms[roomNum]._view[i]);
- delete _vm->_rooms[roomNum]._rules;
- _vm->_rooms[roomNum]._rules = nullptr;
- }
+ freeRule(_vm->_rooms[roomNum]._rules);
}
Common::String Resource::translateFileName(Common::String filename) {
@@ -286,6 +274,21 @@ RuleList *Resource::readRule(Common::File *file) {
return rules;
}
+void Resource::freeRule(RuleList *ruleList) {
+ if (!ruleList)
+ return;
+
+ for (RuleList::iterator rule = ruleList->begin(); rule != ruleList->end(); ++rule) {
+ freeAction((*rule)->_actionList);
+ delete[](*rule)->_condition;
+ delete *rule;
+ *rule = nullptr;
+ }
+
+ delete ruleList;
+ ruleList = nullptr;
+}
+
Action *Resource::readAction(Common::File *file) {
char c;
Action *action = nullptr;
@@ -312,7 +315,7 @@ Action *Resource::readAction(Common::File *file) {
for (int i = 0; i < action->_param1; i++) {
tmp = readString(file);
- messages[i] = (char *)malloc(tmp.size()); // FIXME: memory leak!
+ messages[i] = (char *)malloc(tmp.size());
memcpy(messages[i], tmp.c_str(), tmp.size());
}
@@ -320,7 +323,7 @@ Action *Resource::readAction(Common::File *file) {
} else {
Common::String tmp;
tmp = readString(file);
- action->_data = (byte *)malloc(tmp.size()); // FIXME: memory leak!
+ action->_data = (byte *)malloc(tmp.size());
memcpy(action->_data, tmp.c_str(), tmp.size());
}
@@ -332,6 +335,21 @@ Action *Resource::readAction(Common::File *file) {
return head;
}
+void Resource::freeAction(Action *action) {
+ while (action) {
+ Action *nextAction = action->_nextAction;
+ if (action->_actionType == SHOWMESSAGES) {
+ char **messages = (char **)action->_data;
+ for (int i = 0; i < action->_param1; i++)
+ free(messages[i]);
+ free(messages);
+ } else
+ free(action->_data);
+ delete action;
+ action = nextAction;
+ }
+}
+
CloseData *Resource::readCloseUps(uint16 depth, Common::File *file) {
char c;
CloseData *closeup = nullptr;
@@ -364,6 +382,15 @@ CloseData *Resource::readCloseUps(uint16 depth, Common::File *file) {
return head;
}
+void Resource::freeCloseUps(CloseData *closeUps) {
+ while (closeUps) {
+ CloseData *nextCloseUp = closeUps->_nextCloseUp;
+ freeCloseUps(closeUps->_subCloseUps);
+ delete closeUps;
+ closeUps = nextCloseUp;
+ }
+}
+
ViewData *Resource::readView(Common::File *file) {
char c;
ViewData *view = nullptr;
@@ -390,4 +417,14 @@ ViewData *Resource::readView(Common::File *file) {
return head;
}
+void Resource::freeView(ViewData *view) {
+ while (view) {
+ ViewData *nextView = view->_nextCondition;
+ delete[] view->_condition;
+ freeCloseUps(view->_closeUps);
+ delete view;
+ view = nextView;
+ }
+}
+
} // End of namespace Lab
diff --git a/engines/lab/resource.h b/engines/lab/resource.h
index 37f8b4dae0..26607f23c7 100644
--- a/engines/lab/resource.h
+++ b/engines/lab/resource.h
@@ -111,9 +111,13 @@ private:
Common::String readString(Common::File *file);
int16 *readConditions(Common::File *file);
RuleList *readRule(Common::File *file);
+ void freeRule(RuleList *ruleList);
Action *readAction(Common::File *file);
+ void freeAction(Action *action);
CloseData *readCloseUps(uint16 depth, Common::File *file);
+ void freeCloseUps(CloseData *closeUps);
ViewData *readView(Common::File *file);
+ void freeView(ViewData *view);
void readStaticText();
Common::String translateFileName(Common::String filename);