Skip to content

Commit bf32bad

Browse files
authored
fix memory leak (#837)
* fix memory leak * Update install_darwin.go * fix undefined symbol * fix undefined symbol * go fmt
1 parent 11acfc0 commit bf32bad

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

certificates/install_darwin.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import "C"
6666
import (
6767
"errors"
6868
"os/exec"
69+
"unsafe"
6970

7071
log "github.com/sirupsen/logrus"
7172

@@ -76,7 +77,9 @@ import (
7677
// if something goes wrong will show a dialog with the error and return an error
7778
func InstallCertificate(cert *paths.Path) error {
7879
log.Infof("Installing certificate: %s", cert)
79-
p := C.installCert(C.CString(cert.String()))
80+
ccert := C.CString(cert.String())
81+
defer C.free(unsafe.Pointer(ccert))
82+
p := C.installCert(ccert)
8083
s := C.GoString(p)
8184
if len(s) != 0 {
8285
oscmd := exec.Command("osascript", "-e", "display dialog \""+s+"\" buttons \"OK\" with title \"Error installing certificates\"")

systray/exec_darwin.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import "C"
4848
import (
4949
"os/exec"
5050
"path/filepath"
51+
"unsafe"
5152

5253
"github.com/sirupsen/logrus"
5354
)
@@ -67,7 +68,9 @@ func execApp(path string, args ...string) error {
6768
C.setCharArray(argv, C.int(i), C.CString(arg))
6869
}
6970

70-
C.runApplication(C.CString(path), argv, argc)
71+
cpath := C.CString(path)
72+
defer C.free(unsafe.Pointer(cpath))
73+
C.runApplication(cpath, argv, argc)
7174

7275
C.freeCharArray(argv, argc)
7376
return nil

0 commit comments

Comments
 (0)