From 2a333000030e07b1795f2a4e27efb147a453deac Mon Sep 17 00:00:00 2001 From: Violet Hynes Date: Wed, 27 Mar 2024 11:15:17 -0400 Subject: [PATCH] VAULT-20403 fix incorrectly deferred resource closure in debug command (#26167) * VAULT-20403 fix incorrectly deferred resource closure in debug command * VAULT-20403 changelog --- changelog/26167.txt | 3 +++ command/debug.go | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelog/26167.txt diff --git a/changelog/26167.txt b/changelog/26167.txt new file mode 100644 index 000000000000..f53d18c9fef6 --- /dev/null +++ b/changelog/26167.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli/debug: Fix resource leak in CLI debug command. +``` \ No newline at end of file diff --git a/command/debug.go b/command/debug.go index 09df88fb4d60..8ad7466e5cc3 100644 --- a/command/debug.go +++ b/command/debug.go @@ -687,17 +687,18 @@ func (c *DebugCommand) collectHostInfo(ctx context.Context) { return } if resp != nil { - defer resp.Body.Close() - secret, err := api.ParseSecret(resp.Body) if err != nil { c.captureError("host", err) + resp.Body.Close() return } if secret != nil && secret.Data != nil { hostEntry := secret.Data c.hostInfoCollection = append(c.hostInfoCollection, hostEntry) } + + resp.Body.Close() } } }