Commit c68b09dc by Russell Belfer

Fix dereference of freed delta

I was accidentally using a value that I had just freed.  This
moves the clearing of the delta internal flags into a better place.
parent a21cbb12
...@@ -18,6 +18,7 @@ static git_diff_delta *diff_delta__dup( ...@@ -18,6 +18,7 @@ static git_diff_delta *diff_delta__dup(
return NULL; return NULL;
memcpy(delta, d, sizeof(git_diff_delta)); memcpy(delta, d, sizeof(git_diff_delta));
GIT_DIFF_FLAG__CLEAR_INTERNAL(delta->flags);
if (d->old_file.path != NULL) { if (d->old_file.path != NULL) {
delta->old_file.path = git_pool_strdup(pool, d->old_file.path); delta->old_file.path = git_pool_strdup(pool, d->old_file.path);
...@@ -361,21 +362,25 @@ static int apply_splits_and_deletes( ...@@ -361,21 +362,25 @@ static int apply_splits_and_deletes(
delta->old_file.flags |= GIT_DIFF_FLAG_VALID_OID; delta->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
} }
/* clean up delta before inserting into new list */
GIT_DIFF_FLAG__CLEAR_INTERNAL(delta->flags);
if (delta->status != GIT_DELTA_COPIED &&
delta->status != GIT_DELTA_RENAMED &&
(delta->status != GIT_DELTA_MODIFIED || actually_split))
delta->similarity = 0;
/* insert into new list */
if (git_vector_insert(&onto, delta) < 0) if (git_vector_insert(&onto, delta) < 0)
goto on_error; goto on_error;
} }
/* cannot return an error past this point */ /* cannot return an error past this point */
/* free deltas from old list that didn't make it to the new one */
git_vector_foreach(&diff->deltas, i, delta) { git_vector_foreach(&diff->deltas, i, delta) {
if ((delta->flags & GIT_DIFF_FLAG__TO_DELETE) != 0) if ((delta->flags & GIT_DIFF_FLAG__TO_DELETE) != 0)
git__free(delta); git__free(delta);
GIT_DIFF_FLAG__CLEAR_INTERNAL(delta->flags);
if (delta->status != GIT_DELTA_COPIED &&
delta->status != GIT_DELTA_RENAMED &&
(delta->status != GIT_DELTA_MODIFIED || actually_split))
delta->similarity = 0;
} }
/* swap new delta list into place */ /* swap new delta list into place */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment