missing freeing previous data struction when new allocation fails
Dana Jansens
dana at orodu.net
Tue Nov 23 14:11:44 PST 2010
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
>
>
More information about the wayland-devel
mailing list