applied patch for memory leak fix provided by Tobias Brink