From cce7e314ec22077a36f18f3a59c405b57c607708 Mon Sep 17 00:00:00 2001 From: ksawarzynski <142413096+ksawarzynski@users.noreply.github.com> Date: Sun, 21 Jul 2024 21:37:13 +0200 Subject: [PATCH] fix segfault on gcp metadata server check (#914) --- internal/gcs/gcs.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/gcs/gcs.go b/internal/gcs/gcs.go index 1c230033..bb3f0c36 100644 --- a/internal/gcs/gcs.go +++ b/internal/gcs/gcs.go @@ -18,7 +18,11 @@ var style aurora.Aurora func IsRunningInGCP() bool { resp, err := http.Get("http://metadata.google.internal") - resp.Body.Close() + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + return err == nil }