Re: [patch] tsearch.3: dispose properly of allocated resources in example code

Michael Kerrisk
2008-09-23T13:56:42Z

André,

On Tue, Sep 23, 2008 at 3:23 PM, André Goddard Rosa
<andre.goddard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> On Tue, Sep 23, 2008 at 3:28 AM, Michael Kerrisk
> <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
>> André,
>>
>> On Sun, Sep 21, 2008 at 8:10 AM, André Goddard Rosa
>> <andre.goddard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>> As there are many users who base their own code on these examples, we
>>> should avoid leaking memory when using functions of tsearch() family.
>>> In the provided example, tsearch() leaks memory whenever it tries to
>>> insert a number which was already inserted before.
>>
>> Thanks. My first patch applied via 'git am'!
>>
>> I applied this patch for man-pages-3.10. (I added
>> #define _GNU_SOURCE
>> since that's required to expose the tdestroy() declaration.)
>>
>
> Hi, Michael!
>
> Very nice, thank you! Good to know that you're using git.

(At last... '-).)

> I appreciate your work in the man pages, they were improved a lot
> since you've started working on them.

Thanks!

> Also, I appreciate your concerns
> regarding paccept().
>
> Notice that I sent two different patches in a sequence (sorry for that).

It's a good thing you mentioned this, since I did _not_ notice that:
you sent two mails at almost the same, with the same description, and
which looked otherwise identical (unless one looked very close), so I
assumed you had accidentally sent the same mail twice. (Best to
change the description a little so I know you are resending a
different patch.)

> This is the first one:
>
>> + else if (!((*(int **) val) == ptr))
>
> and this is the second one:
>
> + else if ((*(int **) val) != ptr)
>
> They work the same, but second is cleaner and simpler ;-)

Okay -- I've fixed the page to use the second version. And you only
just got that one in in time for 3.10!

Thanks,