diff --git a/libraries/liblber/io.c b/libraries/liblber/io.c
index e44a46c..8477794 100644
--- a/libraries/liblber/io.c
+++ b/libraries/liblber/io.c
@@ -128,7 +128,7 @@ ber_write(
 int
 ber_realloc( BerElement *ber, ber_len_t len )
 {
-	ber_len_t	total, offset, sos_offset;
+	ber_len_t	total, offset, sos_offset, rw_offset;
 	char		*buf;
 
 	assert( ber != NULL );
@@ -165,6 +165,7 @@ ber_realloc( BerElement *ber, ber_len_t len )
 	offset = ber->ber_ptr - buf;
 	sos_offset = ber->ber_sos_ptr ? ber->ber_sos_ptr - buf : 0;
 	/* if ber_sos_ptr != NULL, it is > ber_buf so that sos_offset > 0 */
+	rw_offset = ber->ber_rwptr ? ber->ber_rwptr - buf : 0;
 
 	buf = (char *) ber_memrealloc_x( buf, total, ber->ber_memctx );
 	if ( buf == NULL ) {
@@ -176,6 +177,8 @@ ber_realloc( BerElement *ber, ber_len_t len )
 	ber->ber_ptr = buf + offset;
 	if ( sos_offset )
 		ber->ber_sos_ptr = buf + sos_offset;
+	if ( ber->ber_rwptr )
+		ber->ber_rwptr = buf + rw_offset;
 
 	return( 0 );
 }
