@@ -237,7 +237,8 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
237237 int fd = hold_locked_index (& index_lock , 1 );
238238 add_files_to_cache (0 , also ? prefix : NULL , pathspec );
239239 refresh_cache (REFRESH_QUIET );
240- if (write_cache (fd , active_cache , active_nr ))
240+ if (write_cache (fd , active_cache , active_nr ) ||
241+ close_lock_file (& index_lock ))
241242 die ("unable to write new_index file" );
242243 commit_style = COMMIT_NORMAL ;
243244 return index_lock .filename ;
@@ -298,7 +299,8 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
298299 fd = hold_locked_index (& index_lock , 1 );
299300 add_remove_files (& partial );
300301 refresh_cache (REFRESH_QUIET );
301- if (write_cache (fd , active_cache , active_nr ))
302+ if (write_cache (fd , active_cache , active_nr ) ||
303+ close_lock_file (& index_lock ))
302304 die ("unable to write new_index file" );
303305
304306 fd = hold_lock_file_for_update (& false_lock ,
@@ -308,7 +310,8 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
308310 add_remove_files (& partial );
309311 refresh_cache (REFRESH_QUIET );
310312
311- if (write_cache (fd , active_cache , active_nr ))
313+ if (write_cache (fd , active_cache , active_nr ) ||
314+ close_lock_file (& false_lock ))
312315 die ("unable to write temporary index file" );
313316 return false_lock .filename ;
314317}
0 commit comments