aoc: Fix memory management issues.