--- Unified2File.c.orig 2015-09-10 09:36:35.103000000 -0700 +++ Unified2File.c 2015-09-10 09:58:34.475000000 -0700 @@ -108,15 +108,19 @@ if(!u2_file->u2_record) { /* XXX we should check that we are in the HEADER_READY state */ - if(!(u2_file->u2_record = (Unified2Record *)calloc(1, - sizeof(Unified2Record)))) - { - fprintf(stderr, "Out of memory (wanted %zu bytes)", - sizeof(Unified2Record)); - return SF_ENOMEM; - } - u2_file->read_offset = 0; - u2_file->read_status = U2FILE_STATUS_HEADER_READY; + if(u2_file->read_status == U2FILE_STATUS_HEADER_READY) + { + u2_file->u2_record = (Unified2Record *) calloc(1, sizeof(Unified2Record)); + + if(!u2_file->u2_record) + { + fprintf(stderr, "Out of memory (wanted %zu bytes)", + sizeof(Unified2Record)); + return SF_ENOMEM; + } + u2_file->read_offset = 0; + u2_file->read_status = U2FILE_STATUS_HEADER_READY; + } } if(u2_file->read_status == U2FILE_STATUS_HEADER_READY @@ -176,6 +180,13 @@ { /* Seek back to where we started, in case we want to try again */ off_t rval = lseek(u2_file->fd, (0 - bytes_read), SEEK_CUR); + if (rval == -1) { + fprintf(stderr, "Error on Seek backwards...\n"); + u2_file->read_errno = errno; + u2_file->read_status = U2FILE_STATUS_NOT_READY; + return SF_ESEEK; + } + fprintf(stderr, "Seek backwards %zu bytes, seek returns %ld", bytes_read, rval); error_count++;