Avoid a use-after-free when capitalizing words

https://bugzilla.gnome.org/show_bug.cgi?id=728533