fix memory leak but now memory is very unsafe
not tested