commit: drop useless xstrdup of commit message

When git-commit is asked to reuse a commit message via "-c",
we call read_commit_message, which looks up the commit and
hands back either the re-encoded result, or a copy of the
original. We make a copy in the latter case so that the
ownership semantics of the return value are clear (in either
case, it can be freed).

However, since we return a "const char *", and since the
resulting buffer's lifetime is the same as that of the whole
program, we never bother to free it at all.

Let's just drop the copy. That saves us a copy in the common
case. While it does mean we leak in the re-encode case, it
doesn't matter, since we are relying on program exit to free
the memory anyway.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2013-01-26 04:42:45 -05:00 коммит произвёл Junio C Hamano
Родитель 50a6b54c03
Коммит 200ebe362c
1 изменённых файлов: 1 добавлений и 1 удалений

Просмотреть файл

@ -962,7 +962,7 @@ static const char *read_commit_message(const char *name)
* encodings are identical.
*/
if (out == NULL)
out = xstrdup(commit->buffer);
out = commit->buffer;
return out;
}