]> git.sur5r.net Git - openldap/commitdiff
Plug unlikely memleak (coverity)
authorHoward Chu <hyc@openldap.org>
Tue, 13 Jan 2015 20:56:23 +0000 (20:56 +0000)
committerHoward Chu <hyc@openldap.org>
Tue, 13 Jan 2015 21:13:46 +0000 (21:13 +0000)
libraries/librewrite/subst.c

index 95c509353d06616181e54cff5ec3dadfefed6643..4694836fed435a0e57d40ed99e32af5347514580 100644 (file)
@@ -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<nsub; l++ ) {
+                       free( subs[nsub].bv_val );
+               }
+               free( subs );
+       }
+       if ( submatch ) {
+               for ( l=0; l<nsub; l++ ) {
+                       free( submatch[nsub].ls_map );
+               }
+               free( submatch );
+       }
        free( result );
 
        return s;