X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibrewrite%2Fsubst.c;h=8efed1422090277d06a2b4428ec6d51e59c39088;hb=3e2cf8cae7bec60d0430328c06e8002b2c17572b;hp=a682348768a9d2728804ec0539f5a00407537fd0;hpb=f7a8ddc17e291c94af29a291a637652d396ff664;p=openldap
diff --git a/libraries/librewrite/subst.c b/libraries/librewrite/subst.c
index a682348768..8efed14220 100644
--- a/libraries/librewrite/subst.c
+++ b/libraries/librewrite/subst.c
@@ -1,7 +1,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
- * 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
@@ -155,6 +155,7 @@ rewrite_subst_compile(
tmpsm = ( struct rewrite_submatch * )realloc( submatch,
sizeof( struct rewrite_submatch )*( nsub + 1 ) );
if ( tmpsm == NULL ) {
+ rewrite_map_destroy( &map );
goto cleanup;
}
submatch = tmpsm;
@@ -194,7 +195,6 @@ rewrite_subst_compile(
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 );
@@ -210,11 +210,25 @@ rewrite_subst_compile(
}
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