check for malloc failure (also move malloc up to simplify error recovery)
check for malloc failure (also move malloc up to simplify error recovery)

Noticed by:	Coverity Prevent analysis tool
Reviewed by:	gnn

jrobhoward/SCADAbase,jrobhoward/SCADAbase,jrobhoward/SCADAbase,jrobhoward/SCADAbase,jrobhoward/SCADAbase,jrobhoward/SCADAbase,jrobhoward/SCADAbase,jrobhoward/SCADAbase,jrobhoward/SCADAbase,jrobhoward/SCADAbase,jrobhoward/SCADAbase