All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Antill <jantill@redhat.com>
To: Karl MacMillan <kmacmillan@mentalrootkit.com>
Cc: selinux@tycho.nsa.gov
Subject: Re: [PATCH - policyrep] add objpool to libsepol
Date: Thu, 19 Apr 2007 11:57:24 -0400	[thread overview]
Message-ID: <1176998244.19144.87.camel@code.and.org> (raw)
In-Reply-To: <1176996925.13683.29.camel@localhost.localdomain>

[-- Attachment #1: Type: text/plain, Size: 3316 bytes --]

On Thu, 2007-04-19 at 11:35 -0400, Karl MacMillan wrote:
> On Thu, 2007-04-19 at 00:47 -0400, James Antill wrote:
> > On Wed, 2007-04-18 at 21:57 -0400, Karl MacMillan wrote:
> > > +int sepol_objpool_free(struct sepol_handle *h, struct sepol_objpool *s)
> > 
> >  If this is going to be used a lot having only a single "destroy"
> > function that also silently unref's everything it's managing seems
> > "bad".
> 
> I'm only intending to use this in the new policyrep where the lifetime
> of the object pool will be tied to the lifetime of the policy tree. I
> could add a destroy function that just destroys the pool though. I'd
> likely need to add a way to iterate over all of the objects in the pool
> to make this generally useful.

 So, sepol_objpool_del() will never be called? If so it seems better to
have it work like an APR memory pool or obstack etc. where you allocate
a bunch of small objects but only remove the entire thing once.

> > > +	if (ret == SEPOL_OK) {
> > 
> >  This doesn't copy "*obj" and so assumes s->obj_free is used to free the
> > input.
> 
> Yes.
> 
> > > +		return 0;
> > > +	} else if (ret == SEPOL_EEXIST) {
> > > +		free(refcount);
> > > +		s->obj_free(*obj);
> > > +		*obj = cur->key;
> > > +		refcount = cur->datum;
> > > +		*refcount += 1;
> > > +		return 0;
> > 
> >  This also assumes s->obj_free is the correct thing to use for the
> > input.
> 
> Yes - that is intentional to avoid additional copying. Are you pointing
> out a problem, or just suggesting the constraint needs documentation?

 I guess I just wonder why have the s->obj_free member at all, esp.
given the examples used with strdup() ... I kind of assumed you expected
input from strdup(), given the examples, and so was confused about the
non-useage of free().
 It also just seems wrong to have the member free function used for
input ... but if you have a use case feel free to ignore me :).

> > > +	} else {
> > > +		free(refcount);
> > > +		return ret;
> > > +	}
> > > +}
> > [...]
> > > +int sepol_objpool_del(struct sepol_handle *h, struct sepol_objpool *s, void *obj)
> > > +{
> > > +	int ret;
> > > +	unsigned int *refcount;
> > > +	
> > > +	refcount = hashtab_search(s->objs, obj);
> > > +	if (refcount == NULL)
> > > +		return SEPOL_ENOENT;
> > > +	
> > > +	(*refcount)--;
> > > +	if (*refcount == 0) {
> > > +		ret = hashtab_remove(s->objs, obj,
> > > +				     sepol_objpool_hashtab_free, s);
> > > +		if (ret != SEPOL_OK)
> > > +			return ret;
> > > +	}
> > 
> >  The only thing hashtab_remove() returns, apart from _OK, is _ENOENT ...
> > which would mean it could be unref'd or not ... if hashtab_remove()
> > could return it in this codepath.
> 
> Not certain what you mean. Generally, these APIs aren't thread safe so I
> assume that the remove will succeed here. The error checking is for
> future changes in the hashtab implementation.

 Sorry, bad English on my part. My point was that I don't see how
hashtab_remove() could ever return in error here (as you've already made
sure it is there) ... and even if it ever did return in error at some
future point, you are leaking a reference count (*refcount == 0, but
there is still one reference in the hashtab).

-- 
James Antill <jantill@redhat.com>

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2007-04-19 16:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-19  1:57 [PATCH - policyrep] add objpool to libsepol Karl MacMillan
2007-04-19  4:47 ` James Antill
2007-04-19 15:35   ` Karl MacMillan
2007-04-19 15:57     ` James Antill [this message]
2007-04-19 16:11       ` Karl MacMillan
2007-04-19 16:58         ` James Antill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1176998244.19144.87.camel@code.and.org \
    --to=jantill@redhat.com \
    --cc=kmacmillan@mentalrootkit.com \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.