Merge commit '30dfc1dad4285e7362ce3f596d7c5d5d9b7fb33d'
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 12 Jun 2015 20:45:53 +0000 (22:45 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Fri, 12 Jun 2015 20:46:10 +0000 (22:46 +0200)
* commit '30dfc1dad4285e7362ce3f596d7c5d5d9b7fb33d':
  cws2fws: Close file handles on error

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
tools/cws2fws.c

diff --cc tools/cws2fws.c
@@@ -59,13 -58,10 +58,13 @@@ int main(int argc, char *argv[]
  
      if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') {
          printf("Not a compressed flash file\n");
-         return 1;
+         goto out;
      }
  
 -    fstat(fd_in, &statbuf);
 +    if (fstat(fd_in, &statbuf) < 0) {
 +        perror("fstat failed");
 +        return 1;
 +    }
      comp_len   = statbuf.st_size;
      uncomp_len = buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24);
  
          buf_in[2] = ((zstream.total_out + 8) >> 16) & 0xff;
          buf_in[3] = ((zstream.total_out + 8) >> 24) & 0xff;
  
 -        lseek(fd_out, 4, SEEK_SET);
 -        if (write(fd_out, &buf_in, 4) < 4) {
 +        if (   lseek(fd_out, 4, SEEK_SET) < 0
 +            || write(fd_out, &buf_in, 4) < 4) {
              perror("Error writing output file");
-             return 1;
+             inflateEnd(&zstream);
+             goto out;
          }
      }