Fix potential leak found by cppcheck

If realloc returns NULL, the original memory is untouched, and if not
otherwise needed, must be freed manually.

This pull request fixes this potential problem in theme.c