fix buffer destructor call
fix memory leaks