Skip to content

Commit 4eb4c19

Browse files
committed
defer freeAlloc
1 parent 197fd54 commit 4eb4c19

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

cmd/opampsupervisor/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ func runInteractive() error {
2828

2929
supervisor, err := supervisor.NewSupervisor(logger, *configFlag)
3030
if err != nil {
31-
logger.Error(err.Error())
32-
os.Exit(-1)
31+
return err
3332
}
3433

3534
err = supervisor.Start()
3635
if err != nil {
37-
logger.Error(err.Error())
38-
os.Exit(-1)
36+
return err
3937
}
4038

4139
interrupt := make(chan os.Signal, 1)

cmd/opampsupervisor/main_windows.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func run() error {
2727
if err := allocConsole(); err != nil {
2828
return fmt.Errorf("alloc console: %w", err)
2929
}
30+
defer func() {
31+
_ = freeConsole()
32+
}()
3033

3134
// No need to supply service name when startup is invoked through
3235
// the Service Control Manager directly.
@@ -35,16 +38,14 @@ func run() error {
3538
// Per https://learn.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-startservicectrldispatchera#return-value
3639
// this means that the process is not running as a service, so run interactively.
3740

38-
// deallocate console if we're not running as service
41+
// manually free console before running interactively
3942
if err = freeConsole(); err != nil {
4043
return fmt.Errorf("free console: %w", err)
4144
}
4245
return runInteractive()
4346
}
44-
4547
return fmt.Errorf("failed to start supervisor: %w", err)
4648
}
47-
4849
return nil
4950
}
5051

@@ -58,7 +59,7 @@ func allocConsole() error {
5859
return nil
5960
}
6061

61-
// deallocate console once we're done with it
62+
// free console once we're done with it
6263
func freeConsole() error {
6364
ret, _, err := freeConsoleProc.Call()
6465
if ret == 0 {

0 commit comments

Comments
 (0)