diff --git a/imagespec.cpp b/imagespec.cpp index 7fb0100..c412a79 100644 --- a/imagespec.cpp +++ b/imagespec.cpp @@ -258,7 +258,7 @@ void ImageSpec_set_channelformats(ImageSpec *spec, TypeDesc* formats){ void ImageSpec_channelnames(ImageSpec *spec, char** out) { std::vector vec = static_cast(spec)->channelnames; for (std::vector::size_type i = 0; i != vec.size(); i++) { - out[i] = (char*)vec[i].c_str(); + out[i] = strdup(vec[i].c_str()); } } diff --git a/imagespec.go b/imagespec.go index 1d66f40..7e6fb20 100644 --- a/imagespec.go +++ b/imagespec.go @@ -391,6 +391,7 @@ func (s *ImageSpec) ChannelNames() []string { C.ImageSpec_channelnames(s.ptr, c_names_ptr) for i, c := range c_names { names[i] = C.GoString(c) + C.free(unsafe.Pointer(c)) } runtime.KeepAlive(s) return names