ITS#10328 librewrite: fix substitution cleanup

This commit is contained in:
Howard Chu 2025-04-22 17:39:05 +01:00 committed by Quanah Gibson-Mount
parent ca5391b811
commit e5a545d54c

View file

@ -131,6 +131,7 @@ rewrite_subst_compile(
map = rewrite_xmap_parse( info,
p + 3, (const char **)&begin );
if ( map == NULL ) {
nsub++; /* make sure subs[nsub] is freed */
goto cleanup;
}
submatch[ nsub ].ls_map = map;
@ -146,6 +147,7 @@ rewrite_subst_compile(
map = rewrite_map_parse( info, p + 2,
(const char **)&begin );
if ( map == NULL ) {
nsub++; /* make sure subs[nsub] is freed */
goto cleanup;
}
p = begin - 1;
@ -165,6 +167,7 @@ rewrite_subst_compile(
continue;
} else {
nsub++; /* make sure subs[nsub] is freed */
goto cleanup;
}
@ -176,10 +179,6 @@ rewrite_subst_compile(
*/
tmps = (struct berval * )realloc( subs, sizeof( struct berval )*( nsub + 1 ) );
if ( tmps == NULL ) {
/*
* XXX need to free the value subst stuff!
*/
free( subs );
goto cleanup;
}
subs = tmps;
@ -200,6 +199,7 @@ rewrite_subst_compile(
s = calloc( sizeof( struct rewrite_subst ), 1 );
if ( s == NULL ) {
nsub++; /* make sure last elements are freed */
goto cleanup;
}
@ -213,13 +213,13 @@ rewrite_subst_compile(
cleanup:;
if ( subs ) {
for ( l=0; l<nsub; l++ ) {
free( subs[nsub].bv_val );
free( subs[l].bv_val );
}
free( subs );
}
if ( submatch ) {
for ( l=0; l<nsub; l++ ) {
free( submatch[nsub].ls_map );
free( submatch[l].ls_map );
}
free( submatch );
}