Skip to content

Commit

Permalink
fix(upstream): writer may be nil when error!=nil (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
hidu authored Jan 4, 2024
1 parent 7dd6059 commit a66d95c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions upstream/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"mime/multipart"
"net/http"
"net/url"
Expand Down Expand Up @@ -132,16 +132,16 @@ func (r *Remote) uploadProfile(j *upstream.UploadJob) error {

writer := multipart.NewWriter(body)
fw, err := writer.CreateFormFile("profile", "profile.pprof")
fw.Write(j.Profile)
if err != nil {
return err
}
fw.Write(j.Profile)
if j.PrevProfile != nil {
fw, err = writer.CreateFormFile("prev_profile", "profile.pprof")
fw.Write(j.PrevProfile)
if err != nil {
return err
}
fw.Write(j.PrevProfile)
}
if j.SampleTypeConfig != nil {
fw, err = writer.CreateFormFile("sample_type_config", "sample_type_config.json")
Expand Down Expand Up @@ -200,7 +200,7 @@ func (r *Remote) uploadProfile(j *upstream.UploadJob) error {
defer response.Body.Close()

// read all the response body
respBody, err := ioutil.ReadAll(response.Body)
respBody, err := io.ReadAll(response.Body)
if err != nil {
return fmt.Errorf("read response body: %v", err)
}
Expand Down

0 comments on commit a66d95c

Please sign in to comment.