Skip to content

Commit

Permalink
cherry pick googleapis#429
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoliangsc committed Mar 26, 2020
1 parent 721295f commit a776606
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gensupport/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ func (mi *MediaInfo) UploadRequest(reqHeaders http.Header, body io.Reader) (newB
fb := readerFunc(body)
fm := readerFunc(media)
combined, ctype := CombineBodyMedia(body, "application/json", media, mi.mType)
toCleanup := []io.Closer{
combined,
}

if fb != nil && fm != nil {
getBody = func() (io.ReadCloser, error) {
rb := ioutil.NopCloser(fb())
Expand All @@ -302,7 +306,11 @@ func (mi *MediaInfo) UploadRequest(reqHeaders http.Header, body io.Reader) (newB
return r, nil
}
}
cleanup = func() { combined.Close() }
cleanup = func() {
for _, closer := range toCleanup {
_ = closer.Close()
}
}
reqHeaders.Set("Content-Type", ctype)
body = combined
}
Expand Down

0 comments on commit a776606

Please sign in to comment.