diff --git a/libraries/libldap/result.c b/libraries/libldap/result.c
index 574ff9449a1850a8f84989bc56ad646ef13f5596..2695143365a3252e83afc83e4e3db37c424ac21f 100644
--- a/libraries/libldap/result.c
+++ b/libraries/libldap/result.c
@@ -484,6 +484,7 @@ retry2:
 #endif
 retry_ber:
 		if ( ber_sockbuf_ctrl( sb, LBER_SB_OPT_DATA_READY, NULL ) ) {
+			ber_free_buf( ber );
 			ber_init2( ber, NULL, ld->ld_lberoptions );
 			goto retry2;
 		}