Fixed a bunch of code warnings produced by clang's static analyser.

1) Various memory leaks, all caused by returning after a malloc
failure without freeing precursor allocations.

2) Fixed potential error in cram_codecs.c where an external block ID
could fail to be found, resulting in dereferencing a null pointer.

3) Improved guards around block IDs to prevent negative blocks (not
found by clang).

4) Removal of dead code; assignments that are no longer used.