Addressed a memory leak issue identified by static analysis.
Corrected an an issue where memcpy might be passed a NULL destination buffer.
Fixed a malloc issue on some systems.
Cast malloc return to appropriate type.