diff --git a/converter.go b/converter.go index 4413847..e6596db 100644 --- a/converter.go +++ b/converter.go @@ -1,6 +1,9 @@ package iconv -// #include +/* +#include +#include +*/ import "C" import ( @@ -16,7 +19,16 @@ type Converter struct { func NewConverter(fromEncoding string, toEncoding string) (converter *Converter, err Error) { converter = new(Converter) - converter.context, err = C.iconv_open(C.CString(toEncoding), C.CString(fromEncoding)) + // create C strings + toEncodingC := C.CString(toEncoding) + fromEncodingC := C.CString(fromEncoding) + + // open an iconv descriptor + converter.context, err = C.iconv_open(toEncodingC, fromEncodingC) + + // free the C Strings + C.free(unsafe.Pointer(toEncodingC)) + C.free(unsafe.Pointer(fromEncodingC)) // check err if err == nil { diff --git a/iconv.go b/iconv.go index 0d65d97..5d1a2f6 100644 --- a/iconv.go +++ b/iconv.go @@ -1,6 +1,8 @@ package iconv -// #include +/* +#include +*/ import "C" import (