replace dangerous uses of strbuf_attach
commite6dfcd6767a58816dacec0df39515803b267fbe6
authorJeff King <peff@peff.net>
Tue, 10 Jun 2014 21:38:38 +0000 (10 17:38 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Jun 2014 17:29:42 +0000 (12 10:29 -0700)
tree4704a591a90b222f057366e24f712e0bee60308b
parent3ffefb54c0515308ceafb6ba071567d9fd379498
replace dangerous uses of strbuf_attach

It is not a good idea to strbuf_attach an arbitrary pointer
just because a function you are calling wants a strbuf.
Attaching implies a transfer of memory ownership; if anyone
were to modify or release the resulting strbuf, we would
free() the pointer, leading to possible problems:

  1. Other users of the original pointer might access freed
     memory.

  2. The pointer might not be the start of a malloc'd
     area, so calling free() on it in the first place would
     be wrong.

In the two cases modified here, we are fortunate that nobody
touches the strbuf once it is attached, but it is an
accident waiting to happen.  Since the previous commit,
commit_tree and friends take a pointer/buf pair, so we can
just do away with the strbufs entirely.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
notes-cache.c
notes-merge.c