From: Tay Ray Chuan Date: Sun, 06 May 2012 15:54:20 GMT Subject: Re: [PATCH 1/4] help.c::uniq: plug a leak Message-ID: In-Reply-To: <20120506081213.GA27878@sigill.intra.peff.net> On Sun, May 6, 2012 at 4:12 PM, Jeff King wrote: > So this shorter patch should be sufficient (though I didn't actually > test it): Tested and works fine. > diff --git a/help.c b/help.c > index 69d483d..d3868b3 100644 > --- a/help.c > +++ b/help.c > @@ -43,9 +43,12 @@ static void uniq(struct cmdnames *cmds) >        if (!cmds->cnt) >                return; > > -       for (i = j = 1; i < cmds->cnt; i++) > -               if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) > +       for (i = j = 1; i < cmds->cnt; i++) { > +               if (!strcmp(cmds->names[i]->name, cmds->names[j-1]->name)) > +                       free(cmds->names[i]); > +               else >                        cmds->names[j++] = cmds->names[i]; > +       } > >        cmds->cnt = j; >  } Not only is this better than mine in terms of readability, it is better than the original code. -- Cheers, Ray Chuan