Fix memory leak: do not add trait duplications to @defined_traits

Closes #588