fix mem leak in libcontainerd/queue/append

Signed-off-by: yangshukui <yangshukui@huawei.com>
This commit is contained in:
yangshukui 2017-06-22 16:47:47 +08:00
parent 88bddd46d8
commit 5425a5ab84
2 changed files with 39 additions and 0 deletions

View file

@ -27,5 +27,11 @@ func (q *queue) append(id string, f func()) {
}
f()
close(done)
q.Lock()
if q.fns[id] == done {
delete(q.fns, id)
}
q.Unlock()
}()
}

View file

@ -0,0 +1,33 @@
// +build linux solaris
package libcontainerd
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestSerialization(t *testing.T) {
var (
q queue
serialization = 1
)
q.append("aaa", func() {
//simulate a long time task
time.Sleep(10 * time.Millisecond)
require.EqualValues(t, serialization, 1)
serialization = 2
})
q.append("aaa", func() {
require.EqualValues(t, serialization, 2)
serialization = 3
})
q.append("aaa", func() {
require.EqualValues(t, serialization, 3)
serialization = 4
})
time.Sleep(20 * time.Millisecond)
}