From: Jonathan Nieder Date: Mon, 22 Nov 2010 17:14:34 GMT Subject: Re: [PATCH v2 3/7] url: add str wrapper for end_url_with_slash() Message-ID: <20101122171433.GB2084@burratino> In-Reply-To: <1290433657-4444-4-git-send-email-rctay89@gmail.com> Tay Ray Chuan wrote: > --- a/url.c > +++ b/url.c > @@ -132,3 +132,11 @@ void end_url_with_slash(struct strbuf *buf, const char *url) > if (buf->len && buf->buf[buf->len - 1] != '/') > strbuf_addstr(buf, "/"); > } > + > +void str_end_url_with_slash(const char *url, char **dest) { > + struct strbuf buf = STRBUF_INIT; > + end_url_with_slash(&buf, url); > + if (dest) > + free(*dest); > + *dest = strbuf_detach(&buf, NULL); I think this should be end_url_with_slash(&buf, url); free(*dest); *dest = strbuf_detach(... If dest were NULL, the assignment would segfault anyway. If dest were non-NULL and *dest NULL, the free() would be a no-op.