]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/modify.c
Fix memory leak.
[openldap] / servers / slapd / modify.c
index 38f6038300152a51e87bf4d376bc332345204364..af40315e35c028dbb374e33aaa97d8f58f71e0dd 100644 (file)
@@ -235,7 +235,14 @@ do_modify(
                                global_lastmod == ON)) && !update )
                        {
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-                               rc = slap_mods_opattrs( op, &mods, &text );
+                               Modifications **modstail;
+                               for( modstail = &mods;
+                                       *modstail != NULL;
+                                       modstail = &(*modstail)->sml_next )
+                               {
+                                       /* empty */
+                               }
+                               rc = slap_mods_opattrs( op, modstail, &text );
 #else
                                char *text = "no-user-modification attribute type";
                                rc = add_modified_attrs( op, &mods );
@@ -303,16 +310,19 @@ int slap_modlist2mods(
                mod = (Modifications *)
                        ch_calloc( 1, sizeof(Modifications) );
 
-               ad = mod->sml_desc;
+               /* copy the op */
+               mod->sml_op = ml->ml_op;
 
                /* convert to attribute description */
-               rc = slap_str2ad( ml->ml_type, &ad, text );
+               rc = slap_str2ad( ml->ml_type, &mod->sml_desc, text );
 
                if( rc != LDAP_SUCCESS ) {
                        slap_mods_free( mod );
                        return rc;
                }
 
+               ad = mod->sml_desc;
+
                if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
                        && !slap_ad_is_binary( ad ))
                {
@@ -372,7 +382,7 @@ int slap_modlist2mods(
                         * a rough single value check... an additional check is needed
                         * to catch add of single value to existing single valued attribute
                         */
-                       if( ( ml->ml_op == LDAP_MOD_ADD || ml->ml_op == LDAP_MOD_REPLACE )
+                       if( ( mod->sml_op == LDAP_MOD_ADD || mod->sml_op == LDAP_MOD_REPLACE )
                                && nvals > 1 && is_at_single_value( ad->ad_type ))
                        {
                                slap_mods_free( mod );
@@ -405,6 +415,9 @@ int slap_mods_opattrs(
        int mop = op->o_tag == LDAP_REQ_ADD
                ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
 
+       assert( modtail != NULL );
+       assert( *modtail == NULL );
+
        ldap_pvt_thread_mutex_lock( &gmtime_mutex );
        ltm = gmtime( &now );
        strftime( timebuf, sizeof(timebuf), "%Y%m%d%H%M%SZ", ltm );
@@ -423,7 +436,7 @@ int slap_mods_opattrs(
        if( op->o_tag == LDAP_REQ_ADD ) {
                mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) );
                mod->sml_op = mop;
-               mod->sml_desc = slap_schema.si_ad_creatorsName;
+               mod->sml_desc = ad_dup( slap_schema.si_ad_creatorsName );
                mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof( struct berval * ) );
                mod->sml_bvalues[0] = ber_bvdup( &name );
                mod->sml_bvalues[1] = NULL;
@@ -433,7 +446,7 @@ int slap_mods_opattrs(
 
                mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) );
                mod->sml_op = mop;
-               mod->sml_desc = slap_schema.si_ad_createTimestamp;
+               mod->sml_desc = ad_dup( slap_schema.si_ad_createTimestamp );
                mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof( struct berval * ) );
                mod->sml_bvalues[0] = ber_bvdup( &timestamp );
                mod->sml_bvalues[1] = NULL;
@@ -443,7 +456,7 @@ int slap_mods_opattrs(
 
        mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) );
        mod->sml_op = mop;
-       mod->sml_desc = slap_schema.si_ad_modifiersName;
+       mod->sml_desc = ad_dup( slap_schema.si_ad_modifiersName );
        mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof( struct berval * ) );
        mod->sml_bvalues[0] = ber_bvdup( &name );
        mod->sml_bvalues[1] = NULL;
@@ -452,7 +465,7 @@ int slap_mods_opattrs(
 
        mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) );
        mod->sml_op = mop;
-       mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
+       mod->sml_desc = ad_dup( slap_schema.si_ad_modifyTimestamp );
        mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof( struct berval * ) );
        mod->sml_bvalues[0] = ber_bvdup( &timestamp );
        mod->sml_bvalues[1] = NULL;