libminixfs: fix buf leak
. mfs: add asserts to catch similar problems in the future Change-Id: I939230b8d63f100ac071696425b35496b2169bc4
This commit is contained in:
parent
075dbe55f3
commit
7d6089f32d
2 changed files with 36 additions and 3 deletions
|
@ -619,6 +619,23 @@ void lmfs_rw_scattered(
|
||||||
static iovec_t iovec[NR_IOREQS];
|
static iovec_t iovec[NR_IOREQS];
|
||||||
u64_t pos;
|
u64_t pos;
|
||||||
int iov_per_block;
|
int iov_per_block;
|
||||||
|
int start_in_use = bufs_in_use, start_bufqsize = bufqsize;
|
||||||
|
|
||||||
|
assert(bufqsize >= 0);
|
||||||
|
if(bufqsize == 0) return;
|
||||||
|
|
||||||
|
/* for READING, check all buffers on the list are obtained and held
|
||||||
|
* (count > 0)
|
||||||
|
*/
|
||||||
|
if (rw_flag == READING) {
|
||||||
|
for(i = 0; i < bufqsize; i++) {
|
||||||
|
assert(bufq[i] != NULL);
|
||||||
|
assert(bufq[i]->lmfs_count > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* therefore they are all 'in use' and must be at least this many */
|
||||||
|
assert(start_in_use >= start_bufqsize);
|
||||||
|
}
|
||||||
|
|
||||||
assert(dev != NO_DEV);
|
assert(dev != NO_DEV);
|
||||||
assert(!(fs_block_size % PAGE_SIZE));
|
assert(!(fs_block_size % PAGE_SIZE));
|
||||||
|
@ -700,8 +717,10 @@ void lmfs_rw_scattered(
|
||||||
}
|
}
|
||||||
r -= fs_block_size;
|
r -= fs_block_size;
|
||||||
}
|
}
|
||||||
bufq += nblocks;
|
|
||||||
bufqsize -= nblocks;
|
bufq += i;
|
||||||
|
bufqsize -= i;
|
||||||
|
|
||||||
if (rw_flag == READING) {
|
if (rw_flag == READING) {
|
||||||
/* Don't bother reading more than the device is willing to
|
/* Don't bother reading more than the device is willing to
|
||||||
* give at this time. Don't forget to release those extras.
|
* give at this time. Don't forget to release those extras.
|
||||||
|
@ -720,6 +739,13 @@ void lmfs_rw_scattered(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(rw_flag == READING) {
|
||||||
|
assert(start_in_use >= start_bufqsize);
|
||||||
|
|
||||||
|
/* READING callers assume all bufs are released. */
|
||||||
|
assert(start_in_use - start_bufqsize == bufs_in_use);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*===========================================================================*
|
/*===========================================================================*
|
||||||
|
|
|
@ -297,7 +297,7 @@ int *completed; /* number of bytes copied */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In all cases, bp now points to a valid buffer. */
|
/* In all cases, bp now points to a valid buffer. */
|
||||||
assert(bp);
|
assert(bp != NULL);
|
||||||
|
|
||||||
if (rw_flag == WRITING && chunk != block_size && !block_spec &&
|
if (rw_flag == WRITING && chunk != block_size && !block_spec &&
|
||||||
(off_t) ex64lo(position) >= rip->i_size && off == 0) {
|
(off_t) ex64lo(position) >= rip->i_size && off == 0) {
|
||||||
|
@ -477,6 +477,7 @@ unsigned bytes_ahead; /* bytes beyond position for immediate use */
|
||||||
static unsigned int readqsize = 0;
|
static unsigned int readqsize = 0;
|
||||||
static struct buf **read_q;
|
static struct buf **read_q;
|
||||||
u64_t position_running;
|
u64_t position_running;
|
||||||
|
int inuse_before = lmfs_bufs_in_use();
|
||||||
|
|
||||||
if(readqsize != nr_bufs) {
|
if(readqsize != nr_bufs) {
|
||||||
if(readqsize > 0) {
|
if(readqsize > 0) {
|
||||||
|
@ -512,6 +513,7 @@ unsigned bytes_ahead; /* bytes beyond position for immediate use */
|
||||||
bp = lmfs_get_block_ino(dev, block, PREFETCH, rip->i_num, position);
|
bp = lmfs_get_block_ino(dev, block, PREFETCH, rip->i_num, position);
|
||||||
|
|
||||||
assert(bp != NULL);
|
assert(bp != NULL);
|
||||||
|
assert(bp->lmfs_count > 0);
|
||||||
if (lmfs_dev(bp) != NO_DEV) return(bp);
|
if (lmfs_dev(bp) != NO_DEV) return(bp);
|
||||||
|
|
||||||
/* The best guess for the number of blocks to prefetch: A lot.
|
/* The best guess for the number of blocks to prefetch: A lot.
|
||||||
|
@ -567,6 +569,7 @@ unsigned bytes_ahead; /* bytes beyond position for immediate use */
|
||||||
/* Acquire block buffers. */
|
/* Acquire block buffers. */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
block_t thisblock;
|
block_t thisblock;
|
||||||
|
assert(bp->lmfs_count > 0);
|
||||||
read_q[read_q_size++] = bp;
|
read_q[read_q_size++] = bp;
|
||||||
|
|
||||||
if (--blocks_ahead == 0) break;
|
if (--blocks_ahead == 0) break;
|
||||||
|
@ -583,6 +586,8 @@ unsigned bytes_ahead; /* bytes beyond position for immediate use */
|
||||||
} else {
|
} else {
|
||||||
bp = get_block(dev, block, PREFETCH);
|
bp = get_block(dev, block, PREFETCH);
|
||||||
}
|
}
|
||||||
|
assert(bp);
|
||||||
|
assert(bp->lmfs_count > 0);
|
||||||
if (lmfs_dev(bp) != NO_DEV) {
|
if (lmfs_dev(bp) != NO_DEV) {
|
||||||
/* Oops, block already in the cache, get out. */
|
/* Oops, block already in the cache, get out. */
|
||||||
put_block(bp, FULL_DATA_BLOCK);
|
put_block(bp, FULL_DATA_BLOCK);
|
||||||
|
@ -591,6 +596,8 @@ unsigned bytes_ahead; /* bytes beyond position for immediate use */
|
||||||
}
|
}
|
||||||
lmfs_rw_scattered(dev, read_q, read_q_size, READING);
|
lmfs_rw_scattered(dev, read_q, read_q_size, READING);
|
||||||
|
|
||||||
|
assert(inuse_before == lmfs_bufs_in_use());
|
||||||
|
|
||||||
if(block_spec)
|
if(block_spec)
|
||||||
return get_block(dev, baseblock, NORMAL);
|
return get_block(dev, baseblock, NORMAL);
|
||||||
return(lmfs_get_block_ino(dev, baseblock, NORMAL, rip->i_num, position));
|
return(lmfs_get_block_ino(dev, baseblock, NORMAL, rip->i_num, position));
|
||||||
|
|
Loading…
Reference in a new issue