Skip to content

Commit

Permalink
Merge pull request #4887 from davecheney/fixedbug/14904
Browse files Browse the repository at this point in the history
apiserver/client: work around compiler bug with named return values

Upstream golang/go#14904

Returning a complex variable by value with a mix of named and implicit
returns was throwing off the compiler. This caused the memory occupied
by the return value to be considered dead before the end of the
function, leading to the gc freeing that memory prematurely.

The bug is not believed to not affect any shipping Go 1.6 compiler, but
it seems prudent to work around the compiler issue in our code.

(Review request: http://reviews.vapour.ws/r/4336/)
  • Loading branch information
jujubot committed Mar 24, 2016
2 parents 78faff7 + 234d415 commit 69d8569
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions apiserver/client/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,13 @@ func (context *statusContext) processServices() map[string]params.ServiceStatus
return servicesMap
}

func (context *statusContext) processService(service *state.Service) (processedStatus params.ServiceStatus) {
func (context *statusContext) processService(service *state.Service) params.ServiceStatus {
serviceCharmURL, _ := service.CharmURL()
processedStatus.Charm = serviceCharmURL.String()
processedStatus.Exposed = service.IsExposed()
processedStatus.Life = processLife(service)
var processedStatus = params.ServiceStatus{
Charm: serviceCharmURL.String(),
Exposed: service.IsExposed(),
Life: processLife(service),
}

if latestCharm, ok := context.latestCharms[*serviceCharmURL.WithRevision(-1)]; ok && latestCharm != nil {
if latestCharm.Revision() > serviceCharmURL.Revision {
Expand All @@ -614,20 +616,20 @@ func (context *statusContext) processService(service *state.Service) (processedS
processedStatus.Relations, processedStatus.SubordinateTo, err = context.processServiceRelations(service)
if err != nil {
processedStatus.Err = err
return
return processedStatus
}
networks, err := service.Networks()
if err != nil {
processedStatus.Err = err
return
return processedStatus
}
var cons constraints.Value
if service.IsPrincipal() {
// Only principals can have constraints.
cons, err = service.Constraints()
if err != nil {
processedStatus.Err = err
return
return processedStatus
}
}
// TODO(dimitern): Drop support for this in a follow-up.
Expand All @@ -646,7 +648,7 @@ func (context *statusContext) processService(service *state.Service) (processedS
serviceStatus, err := service.Status()
if err != nil {
processedStatus.Err = err
return
return processedStatus
}
processedStatus.Status.Status = serviceStatus.Status
processedStatus.Status.Info = serviceStatus.Message
Expand Down

0 comments on commit 69d8569

Please sign in to comment.