Subject: Re: potential rtalloc memory leak
To: None <tech-net@NetBSD.org>
From: Rui Paulo <rpaulo@fnop.net>
List: tech-net
Date: 08/14/2006 22:55:16
David Young wrote:
> On Mon, Aug 14, 2006 at 04:46:42PM -0500, David Young wrote:
>> It has always bugged me that rtalloc() can potentially overwrite ro->ro_rt
>> when ro_rt != NULL, without first RTFREE()'ing ro_rt. Will anybody object
>> if I rewrite rtalloc() in this way, and check it in? I will take the
>> printf out just as soon as anyone sees it, but I do want to see if the
>> memory leak that the old code logically implies does actually happen in
>> the wild.
>>
>> I have in mind some other changes to rtalloc(). More on that, later.
>>
>
> Same code, slightly shorter:
>
> /*
> * Packet routing routines.
> */
> void
> rtalloc(struct route *ro)
> {
> if (ro->ro_rt != NULL) {
> if (ro->ro_rt->rt_ifp != NULL &&
> (ro->ro_rt->rt_flags & RTF_UP) != 0)
> return;
> printf("%s: freeing ro_rt\n", __func__);
> RTFREE(ro->ro_rt);
> }
> ro->ro_rt = rtalloc1(&ro->ro_dst, 1);
> }
I prefer this version. It's more easily read.
I have no problems with the check in.