Subject: Re: potential rtalloc memory leak
To: None <tech-net@NetBSD.org>
From: David Young <dyoung@pobox.com>
List: tech-net
Date: 08/14/2006 16:52:14
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);
}

Dave

-- 
David Young             OJC Technologies
dyoung@ojctech.com      Urbana, IL * (217) 278-3933