@@ -523,7 +523,7 @@ static int parse_hunk_body(
523
523
int newlines = hunk -> hunk .new_lines ;
524
524
525
525
for (;
526
- ctx -> remain > 4 && (oldlines || newlines ) &&
526
+ ctx -> remain > 4 && (oldlines || newlines ) &&
527
527
memcmp (ctx -> line , "@@ -" , 4 ) != 0 ;
528
528
parse_advance_line (ctx )) {
529
529
@@ -566,7 +566,9 @@ static int parse_hunk_body(
566
566
567
567
memset (line , 0x0 , sizeof (git_diff_line ));
568
568
569
- line -> content = ctx -> line + prefix ;
569
+ line -> content = git__strndup (ctx -> line + prefix , ctx -> line_len - prefix );
570
+ GITERR_CHECK_ALLOC (line -> content );
571
+
570
572
line -> content_len = ctx -> line_len - prefix ;
571
573
line -> content_offset = ctx -> content_len - ctx -> remain ;
572
574
line -> origin = origin ;
@@ -939,10 +941,21 @@ static int check_patch(git_patch_parsed *patch)
939
941
static void patch_parsed__free (git_patch * p )
940
942
{
941
943
git_patch_parsed * patch = (git_patch_parsed * )p ;
944
+ git_diff_line * line ;
945
+ size_t i ;
942
946
943
947
if (!patch )
944
948
return ;
945
949
950
+ git_array_foreach (patch -> base .lines , i , line )
951
+ git__free ((char * )line -> content );
952
+
953
+ git__free ((char * )patch -> base .binary .old_file .data );
954
+ git__free ((char * )patch -> base .binary .new_file .data );
955
+ git_array_clear (patch -> base .hunks );
956
+ git_array_clear (patch -> base .lines );
957
+ git__free (patch -> base .delta );
958
+
946
959
git__free (patch -> old_prefix );
947
960
git__free (patch -> new_prefix );
948
961
git__free (patch -> header_old_path );
@@ -951,9 +964,6 @@ static void patch_parsed__free(git_patch *p)
951
964
git__free (patch -> rename_new_path );
952
965
git__free (patch -> old_path );
953
966
git__free (patch -> new_path );
954
- git_array_clear (patch -> base .hunks );
955
- git_array_clear (patch -> base .lines );
956
- git__free (patch -> base .delta );
957
967
git__free (patch );
958
968
}
959
969
0 commit comments