Fixed memory leak where substrings would not be released.