[sheepdog] [PATCH 8/8] sheep: initialize reference count of local request

Hitoshi Mitake mitake.hitoshi at gmail.com
Tue Jul 9 07:04:29 CEST 2013


At Tue, 09 Jul 2013 12:26:47 +0900,
MORITA Kazutaka wrote:
> 
> At Tue,  9 Jul 2013 11:36:42 +0900,
> Hitoshi Mitake wrote:
> > 
> > The patches in this series detected a bug in reference counting of
> > request. alloc_local_request() doesn't initialize a reference count of
> > newly allocated request. This patch fixes this problem.
> > 
> > Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
> > ---
> >  sheep/request.c |    2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/sheep/request.c b/sheep/request.c
> > index d06a749..82794d5 100644
> > --- a/sheep/request.c
> > +++ b/sheep/request.c
> > @@ -424,6 +424,8 @@ static struct request *alloc_local_request(void *data, int data_length)
> >  
> >  	INIT_LIST_HEAD(&req->request_list);
> >  
> > +	main_refcnt_inc(&req->refcnt);
> > +
> >  	return req;
> >  }
> 
> Looks correct, but I'm curious how this series detects this bug.  This
> bug looks like a different problem from what this series can detect.

This bug was detected by the assert() in main_refcnt_dec(). If a
refcnt which has a value 0 is decremented, the function fails with the
assert().

The assert() is not an essential part of the series, but it is useful
for detecting such a bug. This is one of the reasons that reference
counters should be wrapped by specialized functions.

Thanks,
Hitoshi



More information about the sheepdog mailing list