github-vet / github-vet/rangeloop-pointer-findings
dingotiles/pivotal-opsmgr-download-mgr: pivnet/lookup.go; 84 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [dingotiles/pivotal-opsmgr-download-mgr](https://www.github.com/dingotiles/pivotal-opsmgr-download-mgr) at [pivnet/lookup.go](https://github.com/dingotiles/pivotal-opsmgr-download-mgr/blob/a50c531a380eb9ec61b8d40b500133367b78a784/pivnet/lookup.go#L333-L416)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable stemcellRelease used in defer or goroutine at line 407
[Click here to see the code in its original context.](https://github.com/dingotiles/pivotal-opsmgr-download-mgr/blob/a50c531a380eb9ec61b8d40b500133367b78a784/pivnet/lookup.go#L333-L416)
Click here to show the 84 line(s) of Go which triggered the analyzer.
```go
for _, stemcellRelease := range releasesResp.Releases {
stemcell := &marketplaces.ProductStemcell{
Slug: "stemcells",
MarketplaceSlug: pivnetAPI.Slug(),
CPI: cpi,
Version: stemcellRelease.Version,
}
stemcell.EULAAcceptanceURL = pivnetAPI.apiURL(fmt.Sprintf("/products/stemcells/releases/%d/eula_acceptance", stemcellRelease.ID))
// 2. look at product_files for one with aws_object_key ~= /bosh-stemcell-*-*.tgz/
req, err = http.NewRequest("GET", pivnetAPI.apiURL(fmt.Sprintf("/products/stemcells/releases/%d/product_files", stemcellRelease.ID)), nil)
if err != nil {
fmt.Println(err.Error())
return
}
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Token %s", pivnetAPI.apiToken))
resp, err = http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err.Error())
return
}
defer resp.Body.Close()
productFilesResp := struct {
ProductFiles []struct {
ID int `json:"id"`
AwsObjectKey string `json:"aws_object_key"`
FileVersion string `json:"file_version"`
Name string `json:"name"`
Links struct {
Self struct {
Href string `json:"href"`
} `json:"self"`
Download struct {
Href string `json:"href"`
} `json:"download"`
SignatureFileDownload struct {
Href interface{} `json:"href"`
} `json:"signature_file_download"`
} `json:"_links"`
} `json:"product_files"`
Links struct {
Self struct {
Href string `json:"href"`
} `json:"self"`
} `json:"_links"`
}{}
err = json.NewDecoder(resp.Body).Decode(&productFilesResp)
if err != nil {
fmt.Println(err.Error())
return
}
stemcell.ReleaseDate = stemcellRelease.ReleaseDate
// bosh-stemcell-3160-vsphere-esxi-ubuntu-trusty-go_agent.tgz
r, _ := regexp.Compile(fmt.Sprintf("bosh-stemcell-.*-%s-.*\\.tgz", stemcell.CPI))
var wg sync.WaitGroup
for _, pf := range productFilesResp.ProductFiles {
productFile := pf
wg.Add(1)
go func() {
defer wg.Done()
fmt.Println("Checking if product file", productFile.AwsObjectKey, "is a", cpi, "stemcell...")
tileTokens := r.FindStringSubmatch(productFile.AwsObjectKey)
if len(tileTokens) > 0 {
stemcell.ProductFileName = productFile.AwsObjectKey
stemcell.ProductFileURL = pivnetAPI.apiURL(fmt.Sprintf("/products/%s/releases/%d/product_files/%d", stemcell.Slug, stemcellRelease.ID, productFile.ID))
fmt.Printf("Found stemcell %s\n", stemcell.ProductFileName)
return
}
}()
}
wg.Wait()
pivnetAPI.stemcells = append(pivnetAPI.stemcells, stemcell)
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: a50c531a380eb9ec61b8d40b500133367b78a784
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.