Fix memory leaks reported by Address Sanitizer.