Fixed memory leaks
Added comment with problem description and two soltions