wireguard-go-bridge: free C strings
Reported-by: Anders Bergh <anders1@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
8c8030e5c7
commit
388e652315
|
@ -28,6 +28,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var loggerFunc unsafe.Pointer
|
var loggerFunc unsafe.Pointer
|
||||||
|
var versionString *C.char
|
||||||
|
|
||||||
type CLogger struct {
|
type CLogger struct {
|
||||||
level C.int
|
level C.int
|
||||||
|
@ -38,13 +39,18 @@ func (l *CLogger) Write(p []byte) (int, error) {
|
||||||
if uintptr(loggerFunc) == 0 {
|
if uintptr(loggerFunc) == 0 {
|
||||||
return 0, errors.New("No logger initialized")
|
return 0, errors.New("No logger initialized")
|
||||||
}
|
}
|
||||||
C.callLogger(loggerFunc, l.level, C.CString("WireGuard/GoBackend/"+l.interfaceName), C.CString(string(p)))
|
tag := C.CString("WireGuard/GoBackend/"+l.interfaceName)
|
||||||
|
message := C.CString(string(p))
|
||||||
|
C.callLogger(loggerFunc, l.level, tag, message)
|
||||||
|
C.free(unsafe.Pointer(tag))
|
||||||
|
C.free(unsafe.Pointer(message))
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var tunnelHandles map[int32]*Device
|
var tunnelHandles map[int32]*Device
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
versionString = C.CString(WireGuardGoVersion)
|
||||||
roamingDisabled = true
|
roamingDisabled = true
|
||||||
tunnelHandles = make(map[int32]*Device)
|
tunnelHandles = make(map[int32]*Device)
|
||||||
signals := make(chan os.Signal)
|
signals := make(chan os.Signal)
|
||||||
|
@ -57,7 +63,9 @@ func init() {
|
||||||
n := runtime.Stack(buf, true)
|
n := runtime.Stack(buf, true)
|
||||||
buf[n] = 0
|
buf[n] = 0
|
||||||
if uintptr(loggerFunc) != 0 {
|
if uintptr(loggerFunc) != 0 {
|
||||||
C.callLogger(loggerFunc, 0, C.CString("WireGuard/GoBackend/Stacktrace"), (*_Ctype_char)(unsafe.Pointer(&buf[0])))
|
tag := C.CString("WireGuard/GoBackend/Stacktrace")
|
||||||
|
C.callLogger(loggerFunc, 0, tag, (*_Ctype_char)(unsafe.Pointer(&buf[0])))
|
||||||
|
C.free(unsafe.Pointer(tag))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +130,7 @@ func wgTurnOff(tunnelHandle int32) {
|
||||||
|
|
||||||
//export wgVersion
|
//export wgVersion
|
||||||
func wgVersion() *C.char {
|
func wgVersion() *C.char {
|
||||||
return C.CString(WireGuardGoVersion)
|
return versionString
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {}
|
func main() {}
|
||||||
|
|
Loading…
Reference in New Issue