Subject: | memory leak (tree->tree_string field) |
Hi All,
I guess I found memory leak in the SuffixTree-0.03:
tree->tree_string field is alloced but isn't freed in
the suffix_tree.c.
The problem can be tested by this script:
##############################################
use SuffixTree;
my $str = "MACKHGYPDVCPICTAVDVTPGFEYLLLADGEWFP" x 1000;
for (my $i = 0; $i < 1000000; $i++) {
my $tree = create_tree($str);
my $query = "VTP";
my $position = find_substring($tree, $query);
printf "%d %d\n", $i, $position;
delete_tree($tree);
}
##############################################
And the problem can be fixed by this patch:
--- SuffixTree-0.03/suffix_tree.c.orig 2005-01-27 11:21:22.000000000 +0100
+++ SuffixTree-0.03/suffix_tree.c 2005-01-27 11:22:20.000000000 +0100
@@ -997,6 +997,7 @@
if(tree == 0)
return;
ST_DeleteSubTree(tree->root);
+ if (tree->tree_string) free(tree->tree_string);
free(tree);
}
Best regards,
Dmitry Samborsky