fix: memory leak in huffman.cpp (#2728)

This commit is contained in:
Piotr Idzik
2024-09-11 03:25:42 +02:00
committed by GitHub
parent 15e3fed924
commit d74f4d33ea

View File

@@ -23,6 +23,14 @@ struct MinHeapNode {
}
};
void deleteAll(const MinHeapNode* const root) {
if (root) {
deleteAll(root->left);
deleteAll(root->right);
delete root;
}
}
// For comparison of
// two heap nodes (needed in min heap)
struct compare {
@@ -85,6 +93,7 @@ void HuffmanCodes(char data[], int freq[], int size) {
// Print Huffman codes using
// the Huffman tree built above
printCodes(minHeap.top(), "");
deleteAll(minHeap.top());
}
// Driver program to test above functions