Free string if it is unused

If the string is already in the dict, we need to free this.

Original fix by @tt33415366.

Closes #256