From ffadf73a47d556a15f7fba40b095734add2f5e85 Mon Sep 17 00:00:00 2001 From: Piotr Kozimor Date: Wed, 21 Apr 2021 18:59:10 +0200 Subject: [PATCH] Check for errors when closing response bodies --- clientapi/routing/register.go | 7 ++++++- clientapi/threepid/threepid.go | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go index b1c7d939a..945fee557 100644 --- a/clientapi/routing/register.go +++ b/clientapi/routing/register.go @@ -348,7 +348,12 @@ func validateEmailIdentity( JSON: jsonerror.Unknown("failed conecting to identity server"), } } - defer resp.Body.Close() + defer func() { + err = resp.Body.Close() + if err != nil { + util.GetLogger(ctx).WithError(err).Error("validateEmailIdentity: unable to close response body") + } + }() switch resp.StatusCode { case 404: return &util.JSONResponse{ diff --git a/clientapi/threepid/threepid.go b/clientapi/threepid/threepid.go index 49cb2ab29..d8cacc294 100644 --- a/clientapi/threepid/threepid.go +++ b/clientapi/threepid/threepid.go @@ -26,6 +26,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/setup/config" + "github.com/matrix-org/util" ) // EmailAssociationRequest represents the request defined at https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken @@ -92,7 +93,12 @@ func CreateSession( if err != nil { return "", err } - defer resp.Body.Close() + defer func() { + err = resp.Body.Close() + if err != nil { + util.GetLogger(ctx).WithError(err).Error("CreateSession: unable to close response body") + } + }() // Error if the status isn't OK if resp.StatusCode != http.StatusOK { @@ -131,7 +137,12 @@ func CheckAssociation( if err != nil { return false, "", "", err } - defer resp.Body.Close() + defer func() { + err = resp.Body.Close() + if err != nil { + util.GetLogger(ctx).WithError(err).Error("CheckAssociation: unable to close response body") + } + }() var respBody struct { Medium string `json:"medium"` ValidatedAt int64 `json:"validated_at"`