diff --git a/CHANGES b/CHANGES
index 43a95c5f871a1f711fe9a6d63b7266ebb5c539bb..05548265a8711a441c03ec14470184dcf2c11633 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,7 @@
 OpenLDAP 2.4 Change Log
 
 OpenLDAP 2.4.24 Engineering
+	Fixed liblber to not close invalid sockets (ITS#6585)
 	Fixed slapd modify to return actual error (ITS#6581)
 	Fixed slapd-bdb entry cache delete failure (ITS#6577)
 
diff --git a/libraries/liblber/sockbuf.c b/libraries/liblber/sockbuf.c
index e1d9e4536a6c1900137e30fdf8f8b52e98e2f9b3..5bd0a1d1643087653c182d52e82eb1f6cc38765e 100644
--- a/libraries/liblber/sockbuf.c
+++ b/libraries/liblber/sockbuf.c
@@ -541,7 +541,8 @@ sb_stream_close( Sockbuf_IO_Desc *sbiod )
 {
 	assert( sbiod != NULL );
 	assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
-	tcp_close( sbiod->sbiod_sb->sb_fd );
+	if ( sbiod->sbiod_sb->sb_fd != AC_SOCKET_INVALID )
+		tcp_close( sbiod->sbiod_sb->sb_fd );
    return 0;
 }
 
@@ -754,7 +755,8 @@ sb_fd_close( Sockbuf_IO_Desc *sbiod )
 	assert( sbiod != NULL );
 	assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
 
-	close( sbiod->sbiod_sb->sb_fd );
+	if ( sbiod->sbiod_sb->sb_fd != AC_SOCKET_INVALID )
+		close( sbiod->sbiod_sb->sb_fd );
 	return 0;
 }
 
@@ -956,8 +958,9 @@ sb_dgram_close( Sockbuf_IO_Desc *sbiod )
 {
 	assert( sbiod != NULL );
 	assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
-
-	tcp_close( sbiod->sbiod_sb->sb_fd );
+  
+	if ( sbiod->sbiod_sb->sb_fd != AC_SOCKET_INVALID )
+		tcp_close( sbiod->sbiod_sb->sb_fd );
 	return 0;
 }