Refactored test
Added memory leak detection for malloc