Skip to content

Commit 200ebe3

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 50a6b54 commit 200ebe3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ static const char *read_commit_message(const char *name)
962962
* encodings are identical.
963963
*/
964964
if (out == NULL)
965-
out = xstrdup(commit->buffer);
965+
out = commit->buffer;
966966
return out;
967967
}
968968

0 commit comments

Comments
 (0)