From bf32bad81b7aa7a3a11e2e84333a35cb849b664a Mon Sep 17 00:00:00 2001 From: XXIV <13811862+thechampagne@users.noreply.github.com> Date: Wed, 4 Oct 2023 17:37:29 +0300 Subject: [PATCH] fix memory leak (#837) * fix memory leak * Update install_darwin.go * fix undefined symbol * fix undefined symbol * go fmt --- certificates/install_darwin.go | 5 ++++- systray/exec_darwin.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/certificates/install_darwin.go b/certificates/install_darwin.go index 765257b91..134a4bc0c 100644 --- a/certificates/install_darwin.go +++ b/certificates/install_darwin.go @@ -66,6 +66,7 @@ import "C" import ( "errors" "os/exec" + "unsafe" log "github.com/sirupsen/logrus" @@ -76,7 +77,9 @@ import ( // if something goes wrong will show a dialog with the error and return an error func InstallCertificate(cert *paths.Path) error { log.Infof("Installing certificate: %s", cert) - p := C.installCert(C.CString(cert.String())) + ccert := C.CString(cert.String()) + defer C.free(unsafe.Pointer(ccert)) + p := C.installCert(ccert) s := C.GoString(p) if len(s) != 0 { oscmd := exec.Command("osascript", "-e", "display dialog \""+s+"\" buttons \"OK\" with title \"Error installing certificates\"") diff --git a/systray/exec_darwin.go b/systray/exec_darwin.go index ba66e0c39..912a736e3 100644 --- a/systray/exec_darwin.go +++ b/systray/exec_darwin.go @@ -48,6 +48,7 @@ import "C" import ( "os/exec" "path/filepath" + "unsafe" "github.com/sirupsen/logrus" ) @@ -67,7 +68,9 @@ func execApp(path string, args ...string) error { C.setCharArray(argv, C.int(i), C.CString(arg)) } - C.runApplication(C.CString(path), argv, argc) + cpath := C.CString(path) + defer C.free(unsafe.Pointer(cpath)) + C.runApplication(cpath, argv, argc) C.freeCharArray(argv, argc) return nil