missing freeing previous data struction when new allocation fails
林昊翔
linhaoxiang at gmail.com
Mon Nov 22 21:22:39 PST 2010
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*.
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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20101123/ef780a02/attachment-0001.html>
More information about the wayland-devel
mailing list