Make fixes to new message serialization methods

Ensure we declare c_data early, and make sure we don't test
uninitialised pointers. Also added a test to ensure we only
realloc when we actually need to.

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>