Skip to content

Commit

Permalink
Copy stack-allocated channel name strings when returning from cpp to go
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfx committed Aug 12, 2018
1 parent 6d49804 commit 91a22bb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion imagespec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void ImageSpec_set_channelformats(ImageSpec *spec, TypeDesc* formats){
void ImageSpec_channelnames(ImageSpec *spec, char** out) {
std::vector<std::string> vec = static_cast<OIIO::ImageSpec*>(spec)->channelnames;
for (std::vector<std::string>::size_type i = 0; i != vec.size(); i++) {
out[i] = (char*)vec[i].c_str();
out[i] = strdup(vec[i].c_str());
}
}

Expand Down
1 change: 1 addition & 0 deletions imagespec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 91a22bb

Please sign in to comment.