Avoid a use-after-free when caplitalizing words

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