Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: fix memory leak after read body from response (#7245)

h3n4lbb173ceac285
diff --git a/backend/plugin/app/feishu/feishu.go b/backend/plugin/app/feishu/feishu.go
index 98c2d11bf2..f421f7d3bf 100644
--- a/backend/plugin/app/feishu/feishu.go
+++ b/backend/plugin/app/feishu/feishu.go
@@ -14,8 +14,10 @@ import (
"time"
"github.com/pkg/errors"
+ "go.uber.org/zap"
"github.com/bytebase/bytebase/backend/common"
+ "github.com/bytebase/bytebase/backend/common/log"
)
// Response code definition in feishu response body.
@@ -385,6 +387,9 @@ func retry(ctx context.Context, client *http.Client, token *string, tokenRefresh
if err != nil {
return 0, nil, "", errors.Wrapf(err, "read response body with status code %d", resp.StatusCode)
}
+ if err := resp.Body.Close(); err != nil {
+ log.Warn("failed to close resp body", zap.Error(err))
+ }
var response struct {
Code int `json:"code"`
diff --git a/backend/plugin/vcs/internal/oauth/oauth.go b/backend/plugin/vcs/internal/oauth/oauth.go
index d08f6e9379..1f6a2bba78 100644
--- a/backend/plugin/vcs/internal/oauth/oauth.go
+++ b/backend/plugin/vcs/internal/oauth/oauth.go
@@ -11,6 +11,9 @@ import (
"strings"
"github.com/pkg/errors"
+ "go.uber.org/zap"
+
+ "github.com/bytebase/bytebase/backend/common/log"
)
// TokenRefresher is a function to refresh the OAuth token and assign back to
@@ -119,6 +122,9 @@ func retry(ctx context.Context, client *http.Client, token *string, tokenRefresh
if err != nil {
return 0, nil, "", errors.Wrapf(err, "read response body with status code %d", resp.StatusCode)
}
+ if err := resp.Body.Close(); err != nil {
+ log.Warn("failed to close resp body", zap.Error(err))
+ }
if err = getOAuthErrorDetails(resp.StatusCode, body); err != nil {
if _, ok := err.(*oauthError); ok {