Fixed memory leak and access violation
Merge pull request #357 from elliot-forty-two/access-leak-fix

Fixed memory leak and access violation