path: root/stand/libsa/ufs.c
diff options
authorKirk McKusick <mckusick@FreeBSD.org>2018-03-02 04:34:53 +0000
committerKirk McKusick <mckusick@FreeBSD.org>2018-03-02 04:34:53 +0000
commitefbf39642633b46e0c4c7bb9493b4887867a08db (patch)
tree069b58ad67967afaf88953cb1c8c6a83bc5aad70 /stand/libsa/ufs.c
parent972c7fcd3f16ab0894ea3587c7738fb5c0017d53 (diff)
This change is some refactoring of Mark Johnston's changes in r329375
to fix the memory leak that I introduced in r328426. Instead of trying to clear up the possible memory leak in all the clients, I ensure that it gets cleaned up in the source (e.g., ffs_sbget ensures that memory is always freed if it returns an error). The original change in r328426 was a bit sparse in its description. So I am expanding on its description here (thanks cem@ and rgrimes@ for your encouragement for my longer commit messages). In preparation for adding check hashing to superblocks, r328426 is a refactoring of the code to get the reading/writing of the superblock into one place. Unlike the cylinder group reading/writing which ends up in two places (ffs_getcg/ffs_geom_strategy in the kernel and cgget/cgput in libufs), I have the core superblock functions just in the kernel (ffs_sbfetch/ffs_sbput in ffs_subr.c which is already imported into utilities like fsck_ffs as well as libufs to implement sbget/sbput). The ffs_sbfetch and ffs_sbput functions take a function pointer to do the actual I/O for which there are four variants: ffs_use_bread / ffs_use_bwrite for the in-kernel filesystem g_use_g_read_data / g_use_g_write_data for kernel geom clients ufs_use_sa_read for the standalone code (stand/libsa/ufs.c but not stand/libsa/ufsread.c which is size constrained) use_pread / use_pwrite for libufs Uses of these interfaces are in the UFS filesystem, geoms journal & label, libsa changes, and libufs. They also permeate out into the filesystem utilities fsck_ffs, newfs, growfs, clri, dump, quotacheck, fsirand, fstyp, and quot. Some of these utilities should probably be converted to directly use libufs (like dumpfs was for example), but there does not seem to be much win in doing so. Tested by: Peter Holm (pho@)
Notes: svn path=/head/; revision=330264
Diffstat (limited to 'stand/libsa/ufs.c')
1 files changed, 1 insertions, 2 deletions
diff --git a/stand/libsa/ufs.c b/stand/libsa/ufs.c
index 3f0d85be13c5..2cad803e3c73 100644
--- a/stand/libsa/ufs.c
+++ b/stand/libsa/ufs.c
@@ -518,7 +518,7 @@ ufs_open(upath, f)
/* read super block */
- if ((rc = ffs_sbget(f, &fs, -1, 0, ufs_use_sa_read)) != 0)
+ if ((rc = ffs_sbget(f, &fs, -1, "stand", ufs_use_sa_read)) != 0)
goto out;
fp->f_fs = fs;
@@ -688,7 +688,6 @@ ufs_use_sa_read(void *devfd, off_t loc, void **bufp, int size)
int error;
f = (struct open_file *)devfd;
- free(*bufp);
if ((*bufp = malloc(size)) == NULL)
return (ENOSPC);
error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, loc / DEV_BSIZE,