Skip to content

Commit 2638e7b

Browse files
committed
Fix file descriptor leak in GCP FGetObject on error paths
In FGetObject, objectFile is opened but never closed when NewReader or io.Copy fails, leaking a file descriptor. Add defer objectFile.Close() after the successful open to ensure the file is always closed, regardless of which error path is taken. The existing explicit Close() on the happy path runs first; the deferred close is a harmless no-op in that case. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent 3bd3c0e commit 2638e7b

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

internal/bucket/gcp/gcp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ func (c *GCSClient) FGetObject(ctx context.Context, bucketName, objectName, loca
229229
if err != nil {
230230
return "", err
231231
}
232+
defer objectFile.Close()
232233

233234
// Get Object data.
234235
objectReader, err := c.Client.Bucket(bucketName).Object(objectName).If(gcpstorage.Conditions{

0 commit comments

Comments
 (0)