rerere: plug conflict ID leaks

The merge_rr string list stores the conflict ID (a hexadecimal string that is used to index into $GIT_DIR/rr-cache) in the .util field of its elements, and when do_plain_rerere() resolves a conflict, the field is cleared. Also, when rerere_forget() recomputes the conflict ID to updates the preimage file, the conflict ID for the path is updated. We forgot to free the existing conflict ID when we did these two operations. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jun 30, 2015 at 13:03 UTC 8d9b5a4ada8b8e187af7dbdc7bc24f6ed774df80
1 file changed +5 -2
rerere.c
+5 -2
@@ -559,6 +559,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
559 fprintf(stderr, "Recorded resolution for '%s'.\n", path);
560 copy_file(rerere_path(name, "postimage"), path, 0666);
561 mark_resolved:
562 + free(rr->items[i].util);
563 rr->items[i].util = NULL;
564 }
565
@@ -627,6 +628,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
628 char *hex;
629 unsigned char sha1[20];
630 int ret;
631 + struct string_list_item *item;
632
633 ret = handle_cache(path, sha1, NULL);
634 if (ret < 1)
@@ -641,8 +643,9 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
643 handle_cache(path, sha1, rerere_path(hex, "preimage"));
644 fprintf(stderr, "Updated preimage for '%s'\n", path);
645
644 -
645 - string_list_insert(rr, path)->util = hex;
646 + item = string_list_insert(rr, path);
647 + free(item->util);
648 + item->util = hex;
649 fprintf(stderr, "Forgot resolution for %s\n", path);
650 return 0;
651 }