From 8a0c70ff61c73efa8ffa115f8d53cf5a4c7055c7 Mon Sep 17 00:00:00 2001 From: Ahsan Barkati Date: Wed, 5 May 2021 22:06:28 +0530 Subject: [PATCH] fix(backup): Free the UidPack after use (#7786) Fix memory leak caused because of not freeing posting list's uidpack. --- worker/restore_map.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/worker/restore_map.go b/worker/restore_map.go index 8fa0ba60ce5..b34054cf2db 100644 --- a/worker/restore_map.go +++ b/worker/restore_map.go @@ -31,6 +31,7 @@ import ( bpb "github.com/dgraph-io/badger/v3/pb" "github.com/dgraph-io/badger/v3/y" + "github.com/dgraph-io/dgraph/codec" "github.com/dgraph-io/dgraph/ee" "github.com/dgraph-io/dgraph/ee/enc" "github.com/dgraph-io/dgraph/posting" @@ -322,9 +323,11 @@ func (m *mapper) processReqCh(ctx context.Context) error { if err := backupPl.Unmarshal(kv.Value); err != nil { return errors.Wrapf(err, "while reading backup posting list") } + pl := posting.FromBackupPostingList(backupPl) - shouldSplit := pl.Size() >= (1<<20)/2 && len(pl.Pack.Blocks) > 1 + defer codec.FreePack(pl.Pack) + shouldSplit := pl.Size() >= (1<<20)/2 && len(pl.Pack.Blocks) > 1 if !shouldSplit || parsedKey.HasStartUid || len(pl.GetSplits()) > 0 { // This covers two cases. // 1. The list is not big enough to be split.