From f25486d1ccec568f61cb77b53d06f8a5558a57be Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Tue, 13 Jan 2015 20:56:23 +0000 Subject: [PATCH] Plug unlikely memleak (coverity) --- libraries/librewrite/subst.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/libraries/librewrite/subst.c b/libraries/librewrite/subst.c index 95c509353d..4694836fed 100644 --- a/libraries/librewrite/subst.c +++ b/libraries/librewrite/subst.c @@ -194,7 +194,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 +209,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