Skip to content

Commit

Permalink
fix memory leak (#837)
Browse files Browse the repository at this point in the history
* fix memory leak

* Update install_darwin.go

* fix undefined symbol

* fix undefined symbol

* go fmt
  • Loading branch information
thechampagne authored Oct 4, 2023
1 parent 11acfc0 commit bf32bad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion certificates/install_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import "C"
import (
"errors"
"os/exec"
"unsafe"

log "github.com/sirupsen/logrus"

Expand All @@ -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\"")
Expand Down
5 changes: 4 additions & 1 deletion systray/exec_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import "C"
import (
"os/exec"
"path/filepath"
"unsafe"

"github.com/sirupsen/logrus"
)
Expand All @@ -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
Expand Down

0 comments on commit bf32bad

Please # to comment.