Updated checkMemLeaks function