diff --git a/bintree.c b/bintree.c index 9205425..59bfa9b 100644 --- a/bintree.c +++ b/bintree.c @@ -26,7 +26,7 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc free(newNode); //Free unused Memory return NULL;; //Memory allocation failed } - newNode->data = data; //Copy Data + memcpy(newNode->data, data, dataSize); //Copy Data newNode->left = NULL; newNode->right = NULL; @@ -74,7 +74,16 @@ void *nextTreeData(TreeNode *root) // Releases all memory resources (including data copies). void clearTree(TreeNode *root) { - + if(root == NULL){ + return; + } + + clearTree(root->right); + clearTree(root->left); + + free(root->data); + free(root); + } // Returns the number of entries in the tree given by root.