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
This commit is contained in:
Fabricio Voznika
2020-09-22 13:45:24 -07:00
committed by gVisor bot
parent 6e5ea605f4
commit 778c367171
+3 -1
View File
@@ -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.