{
struct bz_file *bzf = (struct bz_file *)f->f_fsdata;
- BZ2_bzDecompressEnd(&(bzf->bzf_bzstream));
- close(bzf->bzf_rawfd);
- free(bzf);
+ f->f_fsdata = NULL;
+ if (bzf) {
+ BZ2_bzDecompressEnd(&(bzf->bzf_bzstream));
+ close(bzf->bzf_rawfd);
+ free(bzf);
+ }
return(0);
}
return 0;
out:
+ f->f_fsdata = NULL;
if (fp)
free(fp);
free(buf);
{
struct file *fp = (struct file *)f->f_fsdata;
- f->f_fsdata = 0;
- free(fp);
+ f->f_fsdata = NULL;
+ if (fp)
+ free(fp);
return 0;
}
errno = EBADF;
return (-1);
}
- if (f->f_rabuf != NULL)
+ if (f->f_rabuf != NULL) {
free(f->f_rabuf);
+ f->f_rabuf = NULL;
+ }
if (!(f->f_flags & F_RAW) && f->f_ops)
err1 = (f->f_ops->fo_close)(f);
if (!(f->f_flags & F_NODEV) && f->f_dev)
dos_close(struct open_file *fd)
{
DOS_FILE *f = (DOS_FILE *)fd->f_fsdata;
- DOS_FS *fs = f->fs;
+ DOS_FS *fs;
- f->fs->links--;
- free(f);
- dos_unmount(fs);
+ fd->f_fsdata = NULL;
+ if (f) {
+ fs = f->fs;
+ f->fs = NULL;
+ fs->links--;
+ free(f);
+ dos_unmount(fs);
+ }
return 0;
}
if (path)
free(path);
if (error) {
+ f->f_fsdata = NULL;
if (fp->f_buf)
free(fp->f_buf);
free(fp->f_fs);
static int
zf_open(const char *fname, struct open_file *f)
{
- static char *zfname;
+ char *zfname;
int rawfd;
struct z_file *zf;
char *cp;
if (zfname == NULL)
return(ENOMEM);
sprintf(zfname, "%s.gz", fname);
-
/* Try to open the compressed datafile */
rawfd = open(zfname, O_RDONLY);
free(zfname);
hfs->lru = 0;
hammer_volume_ondisk_t volhead = hread(hfs, HAMMER_ZONE_ENCODE(1, 0));
- if (volhead == NULL)
- return (-1);
#ifdef TESTING
- printf("signature: %svalid\n",
- volhead->vol_signature != HAMMER_FSBUF_VOLUME ?
- "in" :
- "");
- printf("name: %s\n", volhead->vol_name);
+ if (volhead) {
+ printf("signature: %svalid\n",
+ volhead->vol_signature != HAMMER_FSBUF_VOLUME ?
+ "in" :
+ "");
+ printf("name: %s\n", volhead->vol_name);
+ }
#endif
- if (volhead->vol_signature != HAMMER_FSBUF_VOLUME) {
- for (int i = 0; i < NUMCACHE; i++)
+ if (volhead == NULL || volhead->vol_signature != HAMMER_FSBUF_VOLUME) {
+ for (int i = 0; i < NUMCACHE; i++) {
free(hfs->cache[i].data);
+ hfs->cache[i].data = NULL;
+ }
errno = ENODEV;
return (-1);
}
#if DEBUG
printf("hclose\n");
#endif
- for (int i = 0; i < NUMCACHE; i++)
- free(hfs->cache[i].data);
+ for (int i = 0; i < NUMCACHE; i++) {
+ if (hfs->cache[i].data) {
+ free(hfs->cache[i].data);
+ hfs->cache[i].data = NULL;
+ }
+ }
}
#endif
hammer_open(const char *path, struct open_file *f)
{
struct hfile *hf = malloc(sizeof(*hf));
- bzero(hf, sizeof(*hf));
+ bzero(hf, sizeof(*hf));
f->f_fsdata = hf;
hf->hfs.f = f;
f->f_offset = 0;
int rv = hinit(&hf->hfs);
if (rv) {
+ f->f_fsdata = NULL;
free(hf);
return (rv);
}
#if DEBUG
printf("hammer_open fail\n");
#endif
+ f->f_fsdata = NULL;
hclose(&hf->hfs);
free(hf);
return (ENOENT);
f->f_ops = (struct fs_ops *)0;
f->f_offset = 0;
f->f_devdata = NULL;
- file = (char *)0;
+ f->f_fsdata = NULL;
+ file = NULL;
error = devopen(f, fname, &file);
if (error ||
(((f->f_flags & F_NODEV) == 0) && f->f_dev == (struct devsw *)0))
goto err;
/* see if we opened a raw device; otherwise, 'file' is the file name. */
- if (file == (char *)0 || *file == '\0') {
+ if (file == NULL || *file == '\0') {
f->f_flags |= F_RAW;
return (fd);
}
/* pass file name to the different filesystem open routines */
besterror = ENOENT;
for (i = 0; file_system[i] != NULL; i++) {
-
error = ((*file_system[i]).fo_open)(file, f);
if (error == 0) {
-
f->f_ops = file_system[i];
o_rainit(f);
return (fd);
tftpfile = (struct tftp_handle *) f->f_fsdata;
/* let it time out ... */
-
+ f->f_fsdata = NULL;
if (tftpfile) {
free(tftpfile->path);
free(tftpfile);
if (path)
free(path);
if (rc) {
+ f->f_fsdata = NULL;
if (fp->f_buf)
free(fp->f_buf);
free(fp->f_fs);
#ifdef USEGUARD
if (res->ga_Magic != GAMAGIC)
- panic("free: guard1 fail @ %p", ptr);
+ panic("free: guard1x fail @ %p", ptr);
res->ga_Magic = -1;
#endif
#ifdef USEENDGUARD
if ((res = malloc(size)) != NULL) {
if (ptr) {
old = *(size_t *)((char *)ptr - MALLOCALIGN) - MALLOCALIGN;
+#ifdef USEENDGUARD
+ --old;
+#endif
if (old < size)
bcopy(ptr, res, old);
else
static int
zf_open(const char *fname, struct open_file *f)
{
- static char *zfname;
+ char *zfname;
int rawfd;
struct z_file *zf;
char *cp;
{
if (f->f_devdata != NULL) {
free(f->f_devdata);
+ f->f_devdata = NULL;
}
return(0);
}