fix the bug of possible memory leaks