Fix memory leak related to compound type names

Related to #385, #372.