/*
* Prepare room for submatch expansion
*/
- submatch = calloc( sizeof( struct berval ),
- subst->lt_num_submatch );
- if ( submatch == NULL ) {
- return REWRITE_REGEXEC_ERR;
+ if ( subst->lt_num_submatch > 0 ) {
+ submatch = calloc( sizeof( struct berval ),
+ subst->lt_num_submatch );
+ if ( submatch == NULL ) {
+ return REWRITE_REGEXEC_ERR;
+ }
}
/*
l += subst->lt_subs_len;
res = calloc( sizeof( char ), l + 1 );
if ( res == NULL ) {
- free( submatch );
- return REWRITE_REGEXEC_ERR;
+ rc = REWRITE_REGEXEC_ERR;
+ goto cleanup;
}
/*
val->bv_val = res;
val->bv_len = l;
-
+
+cleanup:;
+ if ( submatch ) {
+ free( submatch );
+ }
+
return rc;
}