Fix use-after-free bug with cached settings values

This patch fixes a couple of use-after-free bugs when caching various
string related setting values.

Fixes: #143