Skip to content

Commit dad9633

Browse files
committed
fix: properly handle response body closing
Put single defer statement right after successful API call to ensure body is closed in all paths. Removes duplicate defer statements.
1 parent 4286467 commit dad9633

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

pkg/github/create_release.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,15 @@ func CreateRelease(getClient GetClientFn, t translations.TranslationHelperFunc)
116116
err,
117117
), nil
118118
}
119+
defer func() { _ = resp.Body.Close() }()
119120

120121
if resp.StatusCode != http.StatusCreated {
121122
body, err := io.ReadAll(resp.Body)
122123
if err != nil {
123124
return nil, fmt.Errorf("failed to read response body: %w", err)
124125
}
125-
defer func() { _ = resp.Body.Close() }()
126126
return mcp.NewToolResultError(fmt.Sprintf("failed to create release: %s", string(body))), nil
127127
}
128-
defer func() { _ = resp.Body.Close() }()
129128

130129
r, err := json.Marshal(release)
131130
if err != nil {

0 commit comments

Comments
 (0)