From 19ecde04ef1ed2ce5fe5d727162bbe7d596e713f Mon Sep 17 00:00:00 2001 From: Shenghui Wu <793703860@qq.com> Date: Thu, 2 Feb 2023 18:23:56 +0800 Subject: [PATCH] util: fix memory leak in chunk allocator (#40989) close pingcap/tidb#40987 --- util/chunk/alloc.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/chunk/alloc.go b/util/chunk/alloc.go index af3385a644389..e9ebaf2e59efd 100644 --- a/util/chunk/alloc.go +++ b/util/chunk/alloc.go @@ -129,11 +129,12 @@ func (a *allocator) Reset() { //column objects and put them to the column allocator for reuse. for id, pool := range a.columnAlloc.pool { - for _, col := range pool.allocColumns { + for i, col := range pool.allocColumns { if (len(pool.freeColumns) < a.columnAlloc.freeColumnsPerType) && checkColumnType(id, col) { col.reset() pool.freeColumns = append(pool.freeColumns, col) } + pool.allocColumns[i] = nil } pool.allocColumns = pool.allocColumns[:0] } @@ -196,6 +197,7 @@ func (cList *columnList) pop() *Column { return nil } col := cList.freeColumns[len(cList.freeColumns)-1] + cList.freeColumns[len(cList.freeColumns)-1] = nil cList.freeColumns = cList.freeColumns[:len(cList.freeColumns)-1] return col }