From f5c0af56d605fdad778db1eecad2ef12ca03760b Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 18 Jan 2015 13:45:38 +0000 Subject: [PATCH] Plug unlikely memleak (coverity) --- libraries/librewrite/subst.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/libraries/librewrite/subst.c b/libraries/librewrite/subst.c index 95c509353d..0e1791c0b9 100644 --- a/libraries/librewrite/subst.c +++ b/libraries/librewrite/subst.c @@ -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