Release buffer also when copyin fails

This commit is contained in:
Frans Kaashoek 2019-08-20 11:57:24 -04:00
parent d9818b89e1
commit 6005ef5a1c

View file

@ -495,8 +495,10 @@ writei(struct inode *ip, int user_src, uint64 src, uint off, uint n)
for(tot=0; tot<n; tot+=m, off+=m, src+=m){
bp = bread(ip->dev, bmap(ip, off/BSIZE));
m = min(n - tot, BSIZE - off%BSIZE);
if(either_copyin(bp->data + (off % BSIZE), user_src, src, m) == -1)
if(either_copyin(bp->data + (off % BSIZE), user_src, src, m) == -1) {
brelse(bp);
break;
}
log_write(bp);
brelse(bp);
}