Fixed incorrect MD5 generation in cram_write_SAM_hdr

Fixed bug where cram_write_SAM_hdr passed a length of zero to MD5_Update,
with the result that the MD5 generated was always that of an empty file.  It
now checks the length again after trying to load the reference so the
correct value is used.

Also check for cram_get_ref returning NULL, and call cram_ref_decr earlier
to avoid a possible memory leak if sam_hdr_update fails.


git-svn-id: svn://svn.code.sf.net/p/staden/code/io_lib@3579 ba6f2710-ca9f-427c-89d3-5bf716dbc8e1