scm_from_locale_stringn() makes an optimization when the length is zero. It returns an immutable string of length zero. For reasons I no longer remember, I had my own ag_scm_string_upcase that called scm_string_upcase_x, presuming that scm_from_locale_stringn had returned a writable string.
Two possible fixes: 1. remove the "optimization" 2. check the length in scm_string_upcase_x before choking. The reason for the seg fault is that scm_backtrace() faulted. I called it in the on_exit path and it couldn't cope.