/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2000-2013 The OpenLDAP Foundation.
+ * Copyright 2000-2017 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
tmpsm = ( struct rewrite_submatch * )realloc( submatch,
sizeof( struct rewrite_submatch )*( nsub + 1 ) );
if ( tmpsm == NULL ) {
+ rewrite_map_destroy( &map );
goto cleanup;
}
submatch = tmpsm;
subs[ nsub ].bv_len = l;
subs[ nsub ].bv_val = malloc( l + 1 );
if ( subs[ nsub ].bv_val == NULL ) {
- free( subs );
goto cleanup;
}
AC_MEMCPY( subs[ nsub ].bv_val, begin, l );
}
s->lt_subs_len = subs_len;
- s->lt_subs = subs;
- s->lt_num_submatch = nsub;
- s->lt_submatch = submatch;
+ s->lt_subs = subs;
+ s->lt_num_submatch = nsub;
+ s->lt_submatch = submatch;
+ subs = NULL;
+ submatch = NULL;
cleanup:;
+ if ( subs ) {
+ for ( l=0; l<nsub; l++ ) {
+ free( subs[nsub].bv_val );
+ }
+ free( subs );
+ }
+ if ( submatch ) {
+ for ( l=0; l<nsub; l++ ) {
+ free( submatch[nsub].ls_map );
+ }
+ free( submatch );
+ }
free( result );
return s;