Fix warning, fix memory leak
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/src/checkout_conflicts.c b/src/checkout_conflicts.c
index dcf2714..eb1ac6e 100644
--- a/src/checkout_conflicts.c
+++ b/src/checkout_conflicts.c
@@ -56,14 +56,16 @@ static int checkout_conflictdata_cmp(const void *a, const void *b)
int checkout_conflictdata_empty(const git_vector *conflicts, size_t idx)
{
- const checkout_conflictdata *conflict;
+ checkout_conflictdata *conflict;
if ((conflict = git_vector_get(conflicts, idx)) == NULL)
return -1;
- return (conflict->ancestor == NULL &&
- conflict->ours == NULL &&
- conflict->theirs == NULL);
+ if (conflict->ancestor || conflict->ours || conflict->theirs)
+ return 0;
+
+ git__free(conflict);
+ return 1;
}
static int checkout_conflicts_load(checkout_data *data, git_vector *conflicts)
@@ -409,8 +411,7 @@ static int checkout_write_entry(
const char *hint_path = NULL, *suffix;
struct stat st;
- assert (side == conflict->ours ||
- side == conflict->theirs);
+ assert (side == conflict->ours || side == conflict->theirs);
git_buf_truncate(&data->path, data->workdir_len);
if (git_buf_puts(&data->path, side->path) < 0)
@@ -423,7 +424,7 @@ static int checkout_write_entry(
if (side == conflict->ours)
suffix = data->opts.our_label ? data->opts.our_label :
"ours";
- else if (side == conflict->theirs)
+ else
suffix = data->opts.their_label ? data->opts.their_label :
"theirs";
@@ -456,7 +457,7 @@ static int checkout_merge_path(
git_merge_file_result *result)
{
const char *our_label_raw, *their_label_raw, *suffix;
- int i = 0, error = 0;
+ int error = 0;
if ((error = git_buf_joinpath(out, git_repository_workdir(data->repo), result->path)) < 0)
return error;