From b6d74ec8a03017654c5f574650c6c4cf950113db Mon Sep 17 00:00:00 2001 From: guangwu Date: Mon, 22 Apr 2024 14:55:33 +0800 Subject: [PATCH] fix: close key files --- pkg/proxy/cert.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/proxy/cert.go b/pkg/proxy/cert.go index d6a1b7d..1654afd 100644 --- a/pkg/proxy/cert.go +++ b/pkg/proxy/cert.go @@ -114,11 +114,13 @@ func LoadOrCreateCA(caKeyFile, caCertFile string) (*x509.Certificate, *rsa.Priva if err != nil { return nil, nil, fmt.Errorf("proxy: could not open cert file for writing: %w", err) } + defer certOut.Close() keyOut, err := os.OpenFile(caKeyFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600) if err != nil { return nil, nil, fmt.Errorf("proxy: could not open key file for writing: %w", err) } + defer keyOut.Close() // Write PEM blocks to CA certificate and key files. if err := pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: caCert.Raw}); err != nil {