Fix invalid free on non-UTF-8 locales