about summary refs log tree commit diff stats
path: root/010vm.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-02-23 10:33:35 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-02-23 10:33:35 -0800
commitf86778e3a26b26674a2854c5842f969113c27c86 (patch)
tree31ae20ba2039a7ba6eb38135e9f6fee5f4e0b7e2 /010vm.cc
parentac2be5254592624c0ea9f82e019b21427688dcb0 (diff)
downloadmu-f86778e3a26b26674a2854c5842f969113c27c86.tar.gz
2692 - all memory leaks fixed
To find this I spent some time trying to diagnose when it happened but
there was no seeming pattern. I'd ended up with a small single-file .cc
and single-file .mu that reproduced one memory leak. Eventually I tried
deleting all type_tree and string_tree from it, and lo the leaks
vanished. I retried on all of edit (just loading), and the leaks
remained gone. At that point I switched tack and started looking at all
the core methods of these classes.
Diffstat (limited to '010vm.cc')
-rw-r--r--010vm.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/010vm.cc b/010vm.cc
index 94570b3a..eb848421 100644
--- a/010vm.cc
+++ b/010vm.cc
@@ -283,7 +283,6 @@ reagent::reagent(const reagent& old) {
   name = old.name;
   value = old.value;
   initialized = old.initialized;
-  properties.clear();
   for (long long int i = 0; i < SIZE(old.properties); ++i) {
     properties.push_back(pair<string, string_tree*>(old.properties.at(i).first,
                                                     old.properties.at(i).second ? new string_tree(*old.properties.at(i).second) : NULL));
@@ -306,12 +305,15 @@ string_tree::string_tree(const string_tree& old) {  // :value(old.value) {
 
 reagent& reagent::operator=(const reagent& old) {
   original_string = old.original_string;
+  for (long long int i = 0; i < SIZE(properties); ++i)
+    if (properties.at(i).second) delete properties.at(i).second;
   properties.clear();
   for (long long int i = 0; i < SIZE(old.properties); ++i)
     properties.push_back(pair<string, string_tree*>(old.properties.at(i).first, old.properties.at(i).second ? new string_tree(*old.properties.at(i).second) : NULL));
   name = old.name;
   value = old.value;
   initialized = old.initialized;
+  if (type) delete type;
   type = old.type ? new type_tree(*old.type) : NULL;
   return *this;
 }