From 2ec2ca34d681cc605142fabcd03efce9a73db76e Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Wed, 26 Oct 2005 02:10:17 +0000 Subject: [PATCH] Arreglo varios memory leaks. --- src/btree.cpp | 23 +++++++++++++++++++---- src/btree_data.cpp | 8 +++++++- src/random.cpp | 2 ++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/btree.cpp b/src/btree.cpp index 8747177..4e00e33 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -393,7 +393,9 @@ void BTree::DelKey (const Clave &k) { std::string s = k; std::cout << "========= Borrando " << s << " =================\n"; - DelKeyR (new BTreeLeafData (k.Clone ()), 0, 0); + BTreeData *b = new BTreeLeafData (k.Clone ()); + DelKeyR (b, 0, 0); + delete b; } void BTree::DelKeyR (BTreeData *k, uint node_num, uint padre) @@ -433,6 +435,8 @@ void BTree::DelKeyR (BTreeData *k, uint node_num, uint padre) std::cout << "Eliminar de Nodo con hijos : " << left << " y " << right << std::endl; DelKeyFromNode (k->getClave (), node_num, padre, left, right); } + DeleteKeys (node_keys); + delete [] node; return; } @@ -469,7 +473,7 @@ void BTree::DelKeyFromLeaf (Clave *k, uint node_num, uint padre) ReadNodoHeader (node, &node_header); node_keys = ReadKeys (node, node_header); - data = new BTreeLeafData (k); + data = new BTreeLeafData (k->Clone ()); std::list::iterator it; it = node_keys.begin (); @@ -530,6 +534,9 @@ void BTree::DelKeyFromLeaf (Clave *k, uint node_num, uint padre) } JoinNodes (join1, join2, padre, tipoh); + + DeleteKeys (node_keys); + delete [] node; return; } @@ -1126,9 +1133,9 @@ BTreeFindResult *BTree::FindKeyR (const Clave *k, uint node_num) BTreeData *data; if (node_header.level == 0) - data = new BTreeLeafData ((Clave *)k); + data = new BTreeLeafData (k->Clone ()); else - data = new BTreeData ((Clave *)k, 0); + data = new BTreeData (k->Clone (), 0); while (it != node_keys.end ()) { if ((*data) == (*(*it))) { @@ -1147,6 +1154,14 @@ BTreeFindResult *BTree::FindKeyR (const Clave *k, uint node_num) it++; } + /* Si llego aca y estoy en nivel 0 (una hoja) quiere + * decir que no lo encontré + */ + if (node_header.level == 0) { + delete data; + return NULL; + } + /* TODO: Aca faltaria liberar memoria */ if (it == posterior) return FindKeyR (k, lchild->getChild ()); diff --git a/src/btree_data.cpp b/src/btree_data.cpp index bf92909..b74427b 100644 --- a/src/btree_data.cpp +++ b/src/btree_data.cpp @@ -24,8 +24,10 @@ BTreeData::BTreeData (Clave *k, uint child) BTreeData::~BTreeData () { - if (clave) + if (clave) { delete clave; + clave = NULL; + } } uint BTreeData::Size () const @@ -89,6 +91,10 @@ BTreeLeafData::BTreeLeafData (uchar *node, int key_type) BTreeLeafData::~BTreeLeafData () { + if (clave) { + delete clave; + clave = NULL; + } } uint BTreeLeafData::Size () const diff --git a/src/random.cpp b/src/random.cpp index b4f1260..8a36882 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -47,6 +47,8 @@ void Random::Ints (std::list &lst, uint n) numeros[random + 3 * n] = true; lst.push_back (random); } + + delete [] numeros; } void Random::Strings (std::list &lst, uint n) -- 2.43.0