From 1bc986423d0b18c8dd1efdf00ae0a2080a12c16c Mon Sep 17 00:00:00 2001 From: Exploding Dragon Date: Thu, 8 Aug 2024 07:28:09 +0000 Subject: [PATCH] fix: rpm sign resource leak (#4878) Fixed the resource leak in #4780. Related: [go-gitea/gitea#31794](https://github.com/go-gitea/gitea/pull/31794) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4878 Reviewed-by: Earl Warren Co-authored-by: Exploding Dragon Co-committed-by: Exploding Dragon --- routers/api/packages/rpm/rpm.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routers/api/packages/rpm/rpm.go b/routers/api/packages/rpm/rpm.go index ca1e8a129d..54fb01c854 100644 --- a/routers/api/packages/rpm/rpm.go +++ b/routers/api/packages/rpm/rpm.go @@ -139,12 +139,14 @@ func UploadPackageFile(ctx *context.Context) { apiError(ctx, http.StatusInternalServerError, err) return } - buf, err = rpm_service.NewSignedRPMBuffer(buf, pri) + signedBuf, err := rpm_service.NewSignedRPMBuffer(buf, pri) if err != nil { // Not in rpm format, parsing failed. apiError(ctx, http.StatusBadRequest, err) return } + defer signedBuf.Close() + buf = signedBuf } pck, err := rpm_module.ParsePackage(buf)