Skip to content

Commit db354b7

Browse files
committed
apply: remove unused call to free() in gitdiff_{old,new}name()
These two functions keep a copy of filename it was given, let gitdiff_verify_name() to rewrite it to a new filename and then free the original if they receive a newly minted filename. However (1) when the original name is NULL, gitdiff_verify_name() returns either NULL or a newly minted value. Either case, we do not have to worry about calling free() on the original NULL. (2) when the original name is not NULL, gitdiff_verify_name() either returns that as-is, or calls die() when it finds inconsistency in the patch. When the function returns, we know that "if ()" statement always is false. Noticed by Christian Couder. Signed-off-by: Junio C Hamano <[email protected]>
1 parent fda3e2c commit db354b7

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

builtin/apply.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -953,21 +953,15 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name,
953953

954954
static int gitdiff_oldname(const char *line, struct patch *patch)
955955
{
956-
char *orig = patch->old_name;
957956
patch->old_name = gitdiff_verify_name(line, patch->is_new, patch->old_name,
958957
DIFF_OLD_NAME);
959-
if (orig != patch->old_name)
960-
free(orig);
961958
return 0;
962959
}
963960

964961
static int gitdiff_newname(const char *line, struct patch *patch)
965962
{
966-
char *orig = patch->new_name;
967963
patch->new_name = gitdiff_verify_name(line, patch->is_delete, patch->new_name,
968964
DIFF_NEW_NAME);
969-
if (orig != patch->new_name)
970-
free(orig);
971965
return 0;
972966
}
973967

0 commit comments

Comments
 (0)