From bb98a9cd2f63cde2e31ed8c7ba626bac55822bd0 Mon Sep 17 00:00:00 2001 From: Adrian Reber Date: Wed, 17 Oct 2018 06:44:24 +0000 Subject: Fix podman port -l Running 'podman port -l' on a system without any containers created gives: $ podman port -l panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0xf3cef1] goroutine 1 [running]: github.com/containers/libpod/libpod.(*Container).State(0x0, 0x0, 0x0, 0x0) /share/go/src/github.com/containers/libpod/libpod/container.go:658 +0x41 main.portCmd(0xc420094580, 0x0, 0x0) /share/go/src/github.com/containers/libpod/cmd/podman/port.go:118 +0x406 This fixes it by making sure the variable 'containers' is nil and not []. Signed-off-by: Adrian Reber --- cmd/podman/port.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cmd') diff --git a/cmd/podman/port.go b/cmd/podman/port.go index d6497d450..3355e751b 100644 --- a/cmd/podman/port.go +++ b/cmd/podman/port.go @@ -104,6 +104,9 @@ func portCmd(c *cli.Context) error { containers = append(containers, container) } else if c.Bool("latest") { container, err = runtime.GetLatestContainer() + if err != nil { + return errors.Wrapf(err, "unable to get last created container") + } containers = append(containers, container) } else { containers, err = runtime.GetRunningContainers() -- cgit v1.2.3-54-g00ecf