reftable: fix resource warning

This would trigger in the unlikely event that we are compacting, and the next available file handle is 0. Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Han-Wen Nienhuys committed Jan 20, 2022 at 15:12 UTC b20aab501788a076b7118946afac4a460bf19d68
1 file changed +5 -5
reftable/stack.c
+5 -5
@@ -877,7 +877,7 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,
877 struct strbuf new_table_path = STRBUF_INIT;
878 int err = 0;
879 int have_lock = 0;
880 - int lock_file_fd = 0;
880 + int lock_file_fd = -1;
881 int compact_count = last - first + 1;
882 char **listp = NULL;
883 char **delete_on_success =
@@ -911,7 +911,7 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,
911 }
912 /* Don't want to write to the lock for now. */
913 close(lock_file_fd);
914 - lock_file_fd = 0;
914 + lock_file_fd = -1;
915
916 have_lock = 1;
917 err = stack_uptodate(st);
@@ -1013,7 +1013,7 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,
1013 goto done;
1014 }
1015 err = close(lock_file_fd);
1016 - lock_file_fd = 0;
1016 + lock_file_fd = -1;
1017 if (err < 0) {
1018 err = REFTABLE_IO_ERROR;
1019 unlink(new_table_path.buf);
@@ -1050,9 +1050,9 @@ done:
1050 listp++;
1051 }
1052 free_names(subtable_locks);
1053 - if (lock_file_fd > 0) {
1053 + if (lock_file_fd >= 0) {
1054 close(lock_file_fd);
1055 - lock_file_fd = 0;
1055 + lock_file_fd = -1;
1056 }
1057 if (have_lock) {
1058 unlink(lock_file_name.buf);