diff --git a/contrib/slapd-modules/comp_match/init.c b/contrib/slapd-modules/comp_match/init.c
index 677dee6cfbb6b33d134d9f511e1ec73fb0dfe555..9226262689c70675715d13319d8eac4bc69c9510 100644
--- a/contrib/slapd-modules/comp_match/init.c
+++ b/contrib/slapd-modules/comp_match/init.c
@@ -760,11 +760,14 @@ comp_component_encoder ( void* mem_op, ComponentSyntaxInfo* csi , struct berval*
 		 * use nibble memory in it 
 		 */
 		free ( bv.bv_val );
+		GenBufFreeBuf( b );
+		BufFreeBuf( buf );
 		return LDAP_SUCCESS;
 	}
 
 	rc = csi->csi_comp_desc->cd_gser_encoder( b, csi );
 	if ( rc < 0 ) {
+		GenBufFreeBuf( b );
 		BufFreeBuf( buf );
 		return rc;
 	}
@@ -780,6 +783,7 @@ comp_component_encoder ( void* mem_op, ComponentSyntaxInfo* csi , struct berval*
 		BufCopy( nval->bv_val, b, size );
 	}
 	ExpBufFreeBuf( buf );
+	GenBufFreeBuf( b );
 
 	return LDAP_SUCCESS;
 }