Use boost::shared_array for memory allocations to fix memory leaks (fix #118)