diff --git a/example/sample6.c b/example/sample6.c index cb02bfdb..0bb10212 100644 --- a/example/sample6.c +++ b/example/sample6.c @@ -1,5 +1,5 @@ /* - $Id: sample6.c,v 1.6 2004/03/20 22:44:14 rocky Exp $ + $Id: sample6.c,v 1.7 2004/03/21 00:57:03 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein @@ -36,22 +36,34 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif + +#include +#include + #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_STDLIB_H #include #endif -#include -#include - +#ifdef HAVE_STDIO_H #include +#endif +#ifdef HAVE_ERRNO_H #include +#endif +#ifdef HAVE_STRING_H #include +#endif +#ifdef HAVE_UNISTD_H #include +#endif +#ifdef HAVE_SYS_TYPES_H #include +#endif #define my_exit(rc) \ + fclose (outfd); \ free(statbuf); \ cdio_destroy(cdio); \ return rc; \ @@ -78,13 +90,16 @@ main(int argc, const char *argv[]) fprintf(stderr, "Could not get ISO-9660 file information for file %s\n", ISO9660_FILENAME); + cdio_destroy(cdio); return 2; } if (!(outfd = fopen ("copying", "wb"))) { perror ("fopen()"); - my_exit(3); + cdio_destroy(cdio); + free(statbuf); + return 3; } /* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */ @@ -121,6 +136,5 @@ main(int argc, const char *argv[]) if (ftruncate (fileno (outfd), statbuf->size)) perror ("ftruncate()"); - fclose (outfd); my_exit(0); } diff --git a/example/sample7.c b/example/sample7.c index 4f8a2e0f..41c5a05e 100644 --- a/example/sample7.c +++ b/example/sample7.c @@ -1,5 +1,5 @@ /* - $Id: sample7.c,v 1.5 2004/03/11 01:31:32 rocky Exp $ + $Id: sample7.c,v 1.6 2004/03/21 00:57:03 rocky Exp $ Copyright (C) 2004 Rocky Bernstein @@ -44,6 +44,9 @@ #ifdef HAVE_ERRNO_H #include #endif +#ifdef HAVE_STDLIB_H +#include +#endif #ifdef HAVE_STRING_H #include #endif @@ -54,6 +57,12 @@ #include #endif +#define my_exit(rc) \ + fclose (outfd); \ + free(statbuf); \ + iso9660_close(iso); \ + return rc; \ + int main(int argc, const char *argv[]) { @@ -75,12 +84,15 @@ main(int argc, const char *argv[]) fprintf(stderr, "Could not get ISO-9660 file information for file %s\n", LOCAL_FILENAME); + iso9660_close(iso); return 2; } if (!(outfd = fopen (LOCAL_FILENAME, "wb"))) { perror ("fopen()"); + free(statbuf); + iso9660_close(iso); return 3; } @@ -97,7 +109,7 @@ main(int argc, const char *argv[]) { fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n", (long unsigned int) statbuf->lsn + (i / ISO_BLOCKSIZE)); - return 4; + my_exit(4); } @@ -106,6 +118,7 @@ main(int argc, const char *argv[]) if (ferror (outfd)) { perror ("fwrite()"); + my_exit(5); return 5; } } @@ -118,7 +131,6 @@ main(int argc, const char *argv[]) if (ftruncate (fileno (outfd), statbuf->size)) perror ("ftruncate()"); - fclose (outfd); - iso9660_close(iso); + my_exit(0); return 0; }