Skip to content

Commit

Permalink
Fix(debug): Close file correctly before exiting on error (#9076)
Browse files Browse the repository at this point in the history
Improving on #9070. A file must be closed if the function exits on an
error.
  • Loading branch information
gcxml authored Apr 22, 2024
1 parent 041ba15 commit 8563a54
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dgraph/cmd/debuginfo/debugging.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ func saveDebug(sourceURL, filePath string, duration time.Duration) error {
glog.Warningf("error closing resp reader: %v", err)
}
}()

out, err := os.Create(filePath)
if err != nil {
return fmt.Errorf("error while creating debug file: %s", err)
}
defer func() {
out.Close()
}()
_, err = io.Copy(out, resp)
return err
}
Expand Down

0 comments on commit 8563a54

Please sign in to comment.