Fixed memory leak (fixed #794)