On Wed, Mar 30, 2016 at 10:06:41AM -0700, Junio C Hamano wrote: > Jeff King <peff@xxxxxxxx> writes: > > > On Tue, Mar 29, 2016 at 09:30:38PM -0400, Eric Sunshine wrote: > > > >> The implementation of strbuf_list_free() is this: > >> > >> struct strbuf **s = sbs; > >> while (*s) { > >> strbuf_release(*s); > >> free(*s++); > >> } > >> free(sbs); > >> > >> which means that wt-status.c is leaking not only 'split', but also > >> each element of split[], right? > > > > Yeah, I didn't notice that, but I think you're right. > > Correct. > > I suspect that we would be better off in the longer term if > we made conscious effort to deprecate and eradicate the use > of strbuf_split* API functions. They are easy to write > crappy code with, inefficient, and error prone. You would > rarely need to have N resulting pieces as strbufs to be > easily manipulatable [*1*]. Yeah, I agree that it is a clunky interface, and I would be happy to see it go away. Many callers would be better off with string_list_split(). When I've looked in the past, though, converting some of the callers was somewhat non-trivial. But in this case... > The function can be written by not using the "split and then > rebuild" pattern, perhaps like so, and the result is even > easier to read and understand, I would say. A sample rewrite > is attached at the end. I agree that the function is much simpler without it. > + /* find the second token on the line */ > + cp = strchr(line->buf, ' '); > + if (!cp) > + return; > + cp++; > + ep = strchr(cp, ' '); > + if (!ep) > + return; Would we ever see "cmd sha1" without a third token? If so, we'd want: ep = strchrnul(cp, ' '); -Peff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html