From f2472de81174b99dfb079d6b2af48c58487a9ebc Mon Sep 17 00:00:00 2001 From: David Pinheiro Date: Mon, 31 Aug 2020 16:41:36 -0700 Subject: [PATCH] Remove duplication of log and memguard init. This change makes the log module configuration and memguard destrutor call to be initialized only once and in the right place. --- cmd/root.go | 8 ++++---- main.go | 9 --------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 8238884..21808c3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -29,10 +29,6 @@ var ( // Execute executes the root command func Execute() error { - // memguard is used to securely keep sensitive information in memory. - // This call makes sure all data will be destroy when the program exits. - defer memguard.Purge() - log.SetOutput(os.Stdout) return rootCmd.Execute() @@ -64,6 +60,10 @@ provide 0 to never give up or a negative number to disable`) } func start(id string, tunnelFlags *alias.TunnelFlags) { + // memguard is used to securely keep sensitive information in memory. + // This call makes sure all data will be destroy when the program exits. + defer memguard.Purge() + if tunnelFlags.Detach { var err error diff --git a/main.go b/main.go index 53f2964..7fa6617 100644 --- a/main.go +++ b/main.go @@ -4,18 +4,9 @@ import ( "os" "github.com/davrodpin/mole/cmd" - - "github.com/awnumar/memguard" - log "github.com/sirupsen/logrus" ) func main() { - // memguard is used to securely keep sensitive information in memory. - // This call makes sure all data will be destroy when the program exits. - defer memguard.Purge() - - log.SetOutput(os.Stdout) - err := cmd.Execute() if err != nil { os.Exit(1)