[PATCH 19/19] ui-shared.c: use struct strbuf instead of fmt()

John Keeping john at keeping.me.uk
Sun Apr 7 14:44:04 CEST 2013


On Sun, Apr 07, 2013 at 02:37:09PM +0200, Jason A. Donenfeld wrote:
> On Sun, Apr 7, 2013 at 11:30 AM, John Keeping <john at keeping.me.uk> wrote:
> >  const char *cgit_hosturl()
> >  {
> > +       struct strbuf sb = STRBUF_INIT;
> >         if (ctx.env.http_host)
> >                 return ctx.env.http_host;
> >         if (!ctx.env.server_name)
> >                 return NULL;
> >         if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80)
> >                 return ctx.env.server_name;
> > -       return xstrdup(fmt("%s:%s", ctx.env.server_name, ctx.env.server_port));
> > +       strbuf_addf(&sb, "%s:%s", ctx.env.server_name, ctx.env.server_port);
> > +       return strbuf_detach(&sb, NULL);
> >  }
> 
> Constness issues, since we're going to want to perhaps deallocate this
> at some point?

I'd prefer to punt that until we fix the leak, since we'll need to do a
bit more than just fix the const as a couple of paths return values that
we either need to xstrdup or not free.




More information about the CGit mailing list