Fix possible memory leaks while using 'realloc'
Merge pull request #229 from rev112/realloc_leak

Fix possible memory leaks while using 'realloc'