Fix for compound type memory leak

Involves #385, #372.