Ensure vmnodes increment the inode ref (before decrementing it)

上级 87263b9c
......@@ -22,7 +22,6 @@ struct vmnode {
atomic<bool> empty;
atomic<char*> page[128];
const enum vmntype type;
struct inode *const ip;
const u64 offset;
const u64 sz;
......@@ -42,6 +41,7 @@ struct vmnode {
NEW_DELETE_OPS(vmnode);
private:
atomic<u64> ref_;
struct inode *const ip;
};
// A mapping of a chunk of an address space to
......
......@@ -159,6 +159,9 @@ exec(const char *path, char **argv, void *ascopev)
if((ip = namei(myproc()->cwd, path)) == 0)
return -1;
auto cleanup = scoped_cleanup([&ip](){
iput(ip);
});
if(myproc()->worker != nullptr)
return -1;
......
......@@ -27,8 +27,11 @@ enum { tlb_lazy = 1 };
vmnode::vmnode(u64 npg, vmntype ntype, inode *i, u64 off, u64 s)
: npages(npg), empty(true), type(ntype),
ip(i), offset(off), sz(s), ref_(0)
offset(off), sz(s), ref_(0), ip(i)
{
if (ip != nullptr)
ip->inc();
if (npg > NELEM(page))
panic("vmnode too big\n");
// XXX Maybe vmnode should take just a byte size
......@@ -46,7 +49,7 @@ vmnode::~vmnode()
for(u64 i = 0; i < npages; i++)
if (page[i])
kfree(page[i]);
if (ip)
if (ip != nullptr)
iput(ip);
}
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论