Merge pull request #2185 from mheon/specfromstate_fix

Do not unmarshal into c.config.Spec
This commit is contained in:
OpenShift Merge Robot
2019-01-18 17:10:51 +01:00
committed by GitHub

View File

@ -415,14 +415,15 @@ func (c *Container) Spec() *spec.Spec {
// config does not exist (e.g., because the container was never started) return // config does not exist (e.g., because the container was never started) return
// the spec from the config. // the spec from the config.
func (c *Container) specFromState() (*spec.Spec, error) { func (c *Container) specFromState() (*spec.Spec, error) {
spec := c.config.Spec returnSpec := c.config.Spec
if f, err := os.Open(c.state.ConfigPath); err == nil { if f, err := os.Open(c.state.ConfigPath); err == nil {
returnSpec = new(spec.Spec)
content, err := ioutil.ReadAll(f) content, err := ioutil.ReadAll(f)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error reading container config") return nil, errors.Wrapf(err, "error reading container config")
} }
if err := json.Unmarshal([]byte(content), &spec); err != nil { if err := json.Unmarshal([]byte(content), &returnSpec); err != nil {
return nil, errors.Wrapf(err, "error unmarshalling container config") return nil, errors.Wrapf(err, "error unmarshalling container config")
} }
} else { } else {
@ -432,7 +433,7 @@ func (c *Container) specFromState() (*spec.Spec, error) {
} }
} }
return spec, nil return returnSpec, nil
} }
// ID returns the container's ID // ID returns the container's ID