Skip to content

Commit 7828b8e

Browse files
authored
fix: memory leak in morrisinorder.cpp (#2729)
1 parent d74f4d3 commit 7828b8e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

data_structures/morrisinorder.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,21 @@ void morrisInorder(Btree *root) {
8181
}
8282
}
8383

84+
void deleteAll(const Btree *const root) {
85+
if (root) {
86+
deleteAll(root->left);
87+
deleteAll(root->right);
88+
delete root;
89+
}
90+
}
91+
8492
int main() {
8593
// Testing morrisInorder funtion
8694
Btree *root = NULL;
8795
int i;
8896
for (i = 1; i <= 7; i++) insert(&root, i);
8997
cout << "Morris Inorder: ";
9098
morrisInorder(root);
99+
deleteAll(root);
91100
return 0;
92101
}

0 commit comments

Comments
 (0)