missing freeing previous data struction when new allocation fails

林昊翔 linhaoxiang at gmail.com
Tue Nov 23 18:44:21 PST 2010


Lock-free reference counting is hard to be implemented on architectures
without double compare-and-swap instruction(one possible solution is binding
counter with the pointer). The overhead of reference counting may be
significant.


Thanks.
Haoxiang Lin
2010/11/24 Dana Jansens <dana at orodu.net>

> 2010/11/23 林昊翔 <linhaoxiang at gmail.com>:
> > I think the best way is borrowing constructor and destructor concepts
> from
> > C++. For each internal data structure foo, maintain a foo_create function
> as
> > the constructor(many data structures are already done), and a foo_destroy
> > function as the destructor. Then we avoid duplicate and complicate clean
> > work at each failure exit in foo_create.
>
> In my own experience, using an unref() (and ref()) - ie. reference
> counting - for all objects, rather than a destroy(), always pays off.
>
> - Dana
>
> > 2010/11/23 Kristian Høgsberg <krh at bitplanet.net>
> >>
> >> On Wed, Nov 17, 2010 at 10:16 PM, 林昊翔 <linhaoxiang at gmail.com> wrote:
> >> > The scenario is:
> >> > struct A *foo()
> >> > {
> >> >     A *a;
> >> >
> >> >     a = malloc(sizeof(A));
> >> >     if (a == NULL)
> >> >         return NULL;
> >> >
> >> >     a->b = malloc(sizeof(B));
> >> >     if (a->b == NULL)
> >> >         return NULL;
> >> >
> >> >     return a;
> >> > }
> >>
> >> You're right, there's a bunch of those in the code.  Could you please
> >> create your patches by committing the changes and then either attach
> >> the output of git format-patch -1 (where -1 means "one commit", use
> >> whatever number of patches you have) or even better use git send-email
> >> -1 --to=wayland-devel at lists.freedesktop.org.
> >>
> >> Thanks,
> >> Kristian
> >
> >
> > _______________________________________________
> > wayland-devel mailing list
> > wayland-devel at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20101124/cd024daa/attachment.html>


More information about the wayland-devel mailing list