Fixes a heap use after delete issue

I was shallow copying a cstring, now i take ownership with a smart pointer
and add a appropriate deleter to take care of it when it is no longer
needed.