From e3bd0f9c3163ef9458e182de1fa5c92bb4fdc0f6 Mon Sep 17 00:00:00 2001 From: Varik Matevosyan Date: Tue, 29 Oct 2024 23:41:29 +0400 Subject: [PATCH] If an error would appear before setting `buildstate->index_file_fd = -1` in `InitBuildState` we would try to close that file descriptor (which would be 0) in `BuildIndexCleanup` function because of condition `if (buildstate->index_file_fd != -1)` and trying to close fd 0 was crashing the server. Now we will check if the fd is greater than 0 before closing it. --- lantern_hnsw/src/hnsw/build.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lantern_hnsw/src/hnsw/build.c b/lantern_hnsw/src/hnsw/build.c index 7c3e75bc..33672dc4 100644 --- a/lantern_hnsw/src/hnsw/build.c +++ b/lantern_hnsw/src/hnsw/build.c @@ -455,7 +455,7 @@ static void BuildIndexCleanup(ldb_HnswBuildState *buildstate) buildstate->external_socket->close(buildstate->external_socket); } - if(buildstate->index_file_fd != -1) { + if(buildstate->index_file_fd > 0) { // index_file_fd will only exist when we mmap the index file to memory if(!buildstate->external && buildstate->index_buffer) { int munmap_ret = munmap(buildstate->index_buffer, buildstate->index_buffer_size);