Skip to content

Commit f976f61

Browse files
dennwcsbinet
authored andcommitted
free allocated strings
1 parent bd44a9e commit f976f61

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

file.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ import "C"
1717

1818
import (
1919
"os"
20+
"unsafe"
2021
)
2122

2223
// FromFile converts a Go file to Python file object.
2324
// Calling close from Python will not close a file descriptor.
2425
func FromFile(f *os.File, mode string) *PyObject {
25-
p := C._gopy_PyFile_FromFile(C.int(f.Fd()), C.CString(f.Name()), C.CString(mode))
26+
cname := C.CString(f.Name())
27+
cmode := C.CString(mode)
28+
p := C._gopy_PyFile_FromFile(C.int(f.Fd()), cname, cmode)
29+
C.free(unsafe.Pointer(cname))
30+
C.free(unsafe.Pointer(cmode))
2631
return togo(p)
2732
}
2833

0 commit comments

Comments
 (0)