Make sure we free our data made by C.CString. Also, updated cgo comments to multiline - seems to be preferred style
This commit is contained in:
parent
690531c87e
commit
20aa6d93c3
16
converter.go
16
converter.go
@ -1,6 +1,9 @@
|
|||||||
package iconv
|
package iconv
|
||||||
|
|
||||||
// #include <iconv.h>
|
/*
|
||||||
|
#include <iconv.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -16,7 +19,16 @@ type Converter struct {
|
|||||||
func NewConverter(fromEncoding string, toEncoding string) (converter *Converter, err Error) {
|
func NewConverter(fromEncoding string, toEncoding string) (converter *Converter, err Error) {
|
||||||
converter = new(Converter)
|
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
|
// check err
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user