KAA-229: Fix memory leaks.