list: fix some possible memory leaks in list implementation