@@ -552,6 +552,7 @@ static void BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, ldb_
552552
553553 if (buildstate -> index_file_path ) {
554554 index_file_fd = open (buildstate -> index_file_path , O_RDONLY );
555+ assert (index_file_fd > 0 );
555556 } else if (buildstate -> external ) {
556557 external_index_receive_index_file (buildstate -> external_socket , & num_added_vectors , & result_buf );
557558 } else {
@@ -565,10 +566,9 @@ static void BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, ldb_
565566 usearch_save (buildstate -> usearch_index , tmp_index_file_path , & error );
566567 assert (error == NULL );
567568 index_file_fd = open (tmp_index_file_path , O_RDONLY );
569+ assert (index_file_fd > 0 );
568570 }
569571
570- assert (index_file_fd > 0 );
571-
572572 if (!buildstate -> external ) {
573573 num_added_vectors = usearch_size (buildstate -> usearch_index , & error );
574574 }
@@ -598,10 +598,9 @@ static void BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, ldb_
598598 munmap_ret = munmap (result_buf , index_file_stat .st_size );
599599 assert (munmap_ret == 0 );
600600 LDB_UNUSED (munmap_ret );
601+ close (index_file_fd );
601602 }
602603
603- close (index_file_fd );
604-
605604 if (buildstate -> external ) {
606605 buildstate -> external_socket -> close (buildstate -> external_socket );
607606 }
0 commit comments