diff --git a/CHANGES b/CHANGES
index 89a2e27b6eafc1a7aeab67098a88fea9b5421b15..3d76add8e2991a2b1e2c6937c313a0cd66b2fd12 100644
--- a/CHANGES
+++ b/CHANGES
@@ -9,6 +9,7 @@ OpenLDAP 2.4.24 Engineering
 	Added slapd-sql autocommit support (ITS#6612)
 	Added slapd-sql support for long long keys (ITS#6617)
 	Fixed liblber to not close invalid sockets (ITS#6585)
+	Fixed liblber error setting (ITS#6732)
 	Fixed libldap dnssrv port format specifier (ITS#6644)
 	Fixed libldap EOF handling (ITS#6723)
 	Fixed libldap GnuTLS hang on socket close (ITS#6673)
diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c
index 96001061fcfdc20e8abd550c046f4d4518808a91..8712031dc54e2d99f46062e5e775c576bf99c41b 100644
--- a/libraries/liblber/memory.c
+++ b/libraries/liblber/memory.c
@@ -201,9 +201,10 @@ ber_memalloc_x( ber_len_t s, void *ctx )
 
 	if( ber_int_memory_fns == NULL || ctx == NULL ) {
 #ifdef LDAP_MEMORY_DEBUG
-		struct ber_mem_hdr *mh = malloc(s + sizeof(struct ber_mem_hdr) + sizeof( ber_int_t));
-		if( mh == NULL ) return NULL;
-
+		new = malloc(s + sizeof(struct ber_mem_hdr) + sizeof( ber_int_t));
+		if( new )
+		{
+		struct ber_mem_hdr *mh = new;
 		mh->bm_top = LBER_MEM_JUNK;
 		mh->bm_length = s;
 		setdatatop( mh);
@@ -222,6 +223,7 @@ ber_memalloc_x( ber_len_t s, void *ctx )
 
 		BER_MEM_VALID( &mh[1] );
 		new = &mh[1];
+		}
 #else
 		new = malloc( s );
 #endif
@@ -254,9 +256,10 @@ ber_memcalloc_x( ber_len_t n, ber_len_t s, void *ctx )
 
 	if( ber_int_memory_fns == NULL || ctx == NULL ) {
 #ifdef LDAP_MEMORY_DEBUG
-		struct ber_mem_hdr *mh = calloc(1,
-			(n * s) + sizeof(struct ber_mem_hdr) + sizeof(ber_int_t) );
-		if( mh == NULL ) return NULL;
+		new = calloc(1, n*s + sizeof(struct ber_mem_hdr) + sizeof(ber_int_t));
+		if( new )
+		{
+		struct ber_mem_hdr *mh = new;
 
 		mh->bm_top = LBER_MEM_JUNK;
 		mh->bm_length = n*s;
@@ -273,6 +276,7 @@ ber_memcalloc_x( ber_len_t n, ber_len_t s, void *ctx )
 #endif
 		BER_MEM_VALID( &mh[1] );
 		new = &mh[1];
+		}
 #else
 		new = calloc( n, s );
 #endif
@@ -487,7 +491,6 @@ ber_dupbv_x(
 		new = dst;
 	} else {
 		if(( new = ber_memalloc_x( sizeof(struct berval), ctx )) == NULL ) {
-			ber_errno = LBER_ERROR_MEMORY;
 			return NULL;
 		}
 	}
@@ -499,7 +502,6 @@ ber_dupbv_x(
 	}
 
 	if(( new->bv_val = ber_memalloc_x( src->bv_len + 1, ctx )) == NULL ) {
-		ber_errno = LBER_ERROR_MEMORY;
 		if ( !dst )
 			ber_memfree_x( new, ctx );
 		return NULL;
@@ -542,7 +544,6 @@ ber_str2bv_x(
 		new = bv;
 	} else {
 		if(( new = ber_memalloc_x( sizeof(struct berval), ctx )) == NULL ) {
-			ber_errno = LBER_ERROR_MEMORY;
 			return NULL;
 		}
 	}
@@ -550,7 +551,6 @@ ber_str2bv_x(
 	new->bv_len = len ? len : strlen( s );
 	if ( dup ) {
 		if ( (new->bv_val = ber_memalloc_x( new->bv_len+1, ctx )) == NULL ) {
-			ber_errno = LBER_ERROR_MEMORY;
 			if ( !bv )
 				ber_memfree_x( new, ctx );
 			return NULL;
@@ -588,7 +588,6 @@ ber_mem2bv_x(
 		new = bv;
 	} else {
 		if(( new = ber_memalloc_x( sizeof(struct berval), ctx )) == NULL ) {
-			ber_errno = LBER_ERROR_MEMORY;
 			return NULL;
 		}
 	}
@@ -596,7 +595,6 @@ ber_mem2bv_x(
 	new->bv_len = len;
 	if ( dup ) {
 		if ( (new->bv_val = ber_memalloc_x( new->bv_len+1, ctx )) == NULL ) {
-			ber_errno = LBER_ERROR_MEMORY;
 			if ( !bv ) {
 				ber_memfree_x( new, ctx );
 			}
@@ -635,13 +633,10 @@ ber_strdup_x( LDAP_CONST char *s, void *ctx )
 	}
 
 	len = strlen( s ) + 1;
-
-	if ( (p = ber_memalloc_x( len, ctx )) == NULL ) {
-		ber_errno = LBER_ERROR_MEMORY;
-		return NULL;
+	if ( (p = ber_memalloc_x( len, ctx )) != NULL ) {
+		AC_MEMCPY( p, s, len );
 	}
 
-	AC_MEMCPY( p, s, len );
 	return p;
 }
 
@@ -677,14 +672,11 @@ ber_strndup_x( LDAP_CONST char *s, ber_len_t l, void *ctx )
 	}
 
 	len = ber_strnlen( s, l );
-
-	if ( (p = ber_memalloc_x( len + 1, ctx )) == NULL ) {
-		ber_errno = LBER_ERROR_MEMORY;
-		return NULL;
+	if ( (p = ber_memalloc_x( len + 1, ctx )) != NULL ) {
+		AC_MEMCPY( p, s, len );
+		p[len] = '\0';
 	}
 
-	AC_MEMCPY( p, s, len );
-	p[len] = '\0';
 	return p;
 }