memory leaks found by valgrind
This commit is contained in:
@@ -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 <rocky@panix.com>
|
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
|
||||||
|
|
||||||
@@ -36,22 +36,34 @@
|
|||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <cdio/cdio.h>
|
||||||
|
#include <cdio/iso9660.h>
|
||||||
|
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_STDLIB_H
|
#ifdef HAVE_STDLIB_H
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
#include <cdio/cdio.h>
|
#ifdef HAVE_STDIO_H
|
||||||
#include <cdio/iso9660.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_ERRNO_H
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define my_exit(rc) \
|
#define my_exit(rc) \
|
||||||
|
fclose (outfd); \
|
||||||
free(statbuf); \
|
free(statbuf); \
|
||||||
cdio_destroy(cdio); \
|
cdio_destroy(cdio); \
|
||||||
return rc; \
|
return rc; \
|
||||||
@@ -78,13 +90,16 @@ main(int argc, const char *argv[])
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Could not get ISO-9660 file information for file %s\n",
|
"Could not get ISO-9660 file information for file %s\n",
|
||||||
ISO9660_FILENAME);
|
ISO9660_FILENAME);
|
||||||
|
cdio_destroy(cdio);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(outfd = fopen ("copying", "wb")))
|
if (!(outfd = fopen ("copying", "wb")))
|
||||||
{
|
{
|
||||||
perror ("fopen()");
|
perror ("fopen()");
|
||||||
my_exit(3);
|
cdio_destroy(cdio);
|
||||||
|
free(statbuf);
|
||||||
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
|
/* 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))
|
if (ftruncate (fileno (outfd), statbuf->size))
|
||||||
perror ("ftruncate()");
|
perror ("ftruncate()");
|
||||||
|
|
||||||
fclose (outfd);
|
|
||||||
my_exit(0);
|
my_exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 <rocky@panix.com>
|
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
||||||
|
|
||||||
@@ -44,6 +44,9 @@
|
|||||||
#ifdef HAVE_ERRNO_H
|
#ifdef HAVE_ERRNO_H
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#ifdef HAVE_STRING_H
|
#ifdef HAVE_STRING_H
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -54,6 +57,12 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define my_exit(rc) \
|
||||||
|
fclose (outfd); \
|
||||||
|
free(statbuf); \
|
||||||
|
iso9660_close(iso); \
|
||||||
|
return rc; \
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
@@ -75,12 +84,15 @@ main(int argc, const char *argv[])
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Could not get ISO-9660 file information for file %s\n",
|
"Could not get ISO-9660 file information for file %s\n",
|
||||||
LOCAL_FILENAME);
|
LOCAL_FILENAME);
|
||||||
|
iso9660_close(iso);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(outfd = fopen (LOCAL_FILENAME, "wb")))
|
if (!(outfd = fopen (LOCAL_FILENAME, "wb")))
|
||||||
{
|
{
|
||||||
perror ("fopen()");
|
perror ("fopen()");
|
||||||
|
free(statbuf);
|
||||||
|
iso9660_close(iso);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +109,7 @@ main(int argc, const char *argv[])
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
|
fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
|
||||||
(long unsigned int) statbuf->lsn + (i / ISO_BLOCKSIZE));
|
(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))
|
if (ferror (outfd))
|
||||||
{
|
{
|
||||||
perror ("fwrite()");
|
perror ("fwrite()");
|
||||||
|
my_exit(5);
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,7 +131,6 @@ main(int argc, const char *argv[])
|
|||||||
if (ftruncate (fileno (outfd), statbuf->size))
|
if (ftruncate (fileno (outfd), statbuf->size))
|
||||||
perror ("ftruncate()");
|
perror ("ftruncate()");
|
||||||
|
|
||||||
fclose (outfd);
|
my_exit(0);
|
||||||
iso9660_close(iso);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user