]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#10328 librewrite: fix substitution cleanup
authorHoward Chu <hyc@openldap.org>
Tue, 22 Apr 2025 16:39:05 +0000 (17:39 +0100)
committerQuanah Gibson-Mount <quanah@openldap.org>
Tue, 6 May 2025 15:54:28 +0000 (15:54 +0000)
libraries/librewrite/subst.c

index 72539206c6dd8603da28562335ac98ee75b6436f..df5acb23dbafec096fbd8a04b696607ad6db174a 100644 (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 );
        }