OSDN Git Service

apply: remove unused call to free() in gitdiff_{old,new}name()
authorJunio C Hamano <gitster@pobox.com>
Tue, 22 Mar 2016 21:41:08 +0000 (14:41 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 22 Mar 2016 21:41:08 +0000 (14:41 -0700)
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 <gitster@pobox.com>
builtin/apply.c

index 465f954..4afc94f 100644 (file)
@@ -953,21 +953,15 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name,
 
 static int gitdiff_oldname(const char *line, struct patch *patch)
 {
-       char *orig = patch->old_name;
        patch->old_name = gitdiff_verify_name(line, patch->is_new, patch->old_name,
                                              DIFF_OLD_NAME);
-       if (orig != patch->old_name)
-               free(orig);
        return 0;
 }
 
 static int gitdiff_newname(const char *line, struct patch *patch)
 {
-       char *orig = patch->new_name;
        patch->new_name = gitdiff_verify_name(line, patch->is_delete, patch->new_name,
                                              DIFF_NEW_NAME);
-       if (orig != patch->new_name)
-               free(orig);
        return 0;
 }