Add (and use) a function mutt_str_replace, which essentially replaces the sequence:
safe_free (&s); s = safe_strdup (t);