Skip to content

Commit

Permalink
If an error would appear before setting buildstate->index_file_fd = -1
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
var77 committed Oct 29, 2024
1 parent cd6c598 commit e3bd0f9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lantern_hnsw/src/hnsw/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e3bd0f9

Please sign in to comment.