From 778c367171f96c6cfd269cd2363c9f608dd96bcb Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Tue, 22 Sep 2020 13:43:02 -0700 Subject: Fix panic in `runsc flags` When printing flags, FlagSet.PrintDefaults compares the Zero value to the flag default value. The Zero refs.LeakMode value was panicking in String() because it didn't expect the default to be used Closes #4023 PiperOrigin-RevId: 333150836 --- pkg/refs/refcounter.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'pkg/refs') diff --git a/pkg/refs/refcounter.go b/pkg/refs/refcounter.go index 57d8542b9..699ea8ac3 100644 --- a/pkg/refs/refcounter.go +++ b/pkg/refs/refcounter.go @@ -257,6 +257,8 @@ func (l *LeakMode) Get() interface{} { // String implements flag.Value. func (l *LeakMode) String() string { switch *l { + case UninitializedLeakChecking: + return "uninitialized" case NoLeakChecking: return "disabled" case LeaksLogWarning: @@ -264,7 +266,7 @@ func (l *LeakMode) String() string { case LeaksLogTraces: return "log-traces" } - panic(fmt.Sprintf("invalid ref leak mode %q", *l)) + panic(fmt.Sprintf("invalid ref leak mode %d", *l)) } // leakMode stores the current mode for the reference leak checker. -- cgit v1.2.3