From: Howard Chu Date: Wed, 2 Jan 2002 12:34:35 +0000 (+0000) Subject: Fix memory leak of Mod.sml_type X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~369 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ee98e6938c19247f3c3b2bfb04bdf77f254c8e0d;p=openldap Fix memory leak of Mod.sml_type --- diff --git a/servers/slapd/add.c b/servers/slapd/add.c index c02e33b6e8..047a61cbf7 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -143,15 +143,12 @@ do_add( Connection *conn, Operation *op ) free( tmp.sml_type.bv_val ); goto done; } - mod = (Modifications *) ch_malloc( sizeof(Modifications) - + tmp.sml_type.bv_len + 1); + mod = (Modifications *) ch_malloc( sizeof(Modifications) ); mod->sml_op = LDAP_MOD_ADD; mod->sml_next = NULL; mod->sml_desc = NULL; - mod->sml_type.bv_val = (char *)(mod+1); - strcpy(mod->sml_type.bv_val, tmp.sml_type.bv_val); - mod->sml_type.bv_len = tmp.sml_type.bv_len; + mod->sml_type = tmp.sml_type; mod->sml_bvalues = tmp.sml_bvalues; *modtail = mod; diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 543594a5d2..ebe470ce5a 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -116,11 +116,8 @@ do_modify( goto cleanup; } - mod = (Modifications *) ch_malloc( sizeof(Modifications) - + tmp.sml_type.bv_len + 1); - mod->sml_type.bv_val = (char *)(mod+1); - strcpy(mod->sml_type.bv_val, tmp.sml_type.bv_val); - mod->sml_type.bv_len = tmp.sml_type.bv_len; + mod = (Modifications *) ch_malloc( sizeof(Modifications) ); + mod->sml_type = tmp.sml_type; mod->sml_bvalues = tmp.sml_bvalues; mod->sml_desc = NULL; *modtail = mod; @@ -595,6 +592,7 @@ int slap_mods_opattrs( if ( tmpval.bv_len ) { mod = (Modifications *) ch_malloc( sizeof( Modifications ) ); mod->sml_op = mop; + mod->sml_type.bv_val = NULL; mod->sml_desc = slap_schema.si_ad_structuralObjectClass; mod->sml_bvalues = (BVarray) ch_malloc( 2 * sizeof( struct berval ) ); ber_dupbv( &mod->sml_bvalues[0], &tmpval ); @@ -609,6 +607,7 @@ int slap_mods_opattrs( mod = (Modifications *) ch_malloc( sizeof( Modifications ) ); mod->sml_op = mop; + mod->sml_type.bv_val = NULL; mod->sml_desc = slap_schema.si_ad_entryUUID; mod->sml_bvalues = (BVarray) ch_malloc( 2 * sizeof( struct berval ) ); ber_dupbv( &mod->sml_bvalues[0], &tmpval ); @@ -619,6 +618,7 @@ int slap_mods_opattrs( mod = (Modifications *) ch_malloc( sizeof( Modifications ) ); mod->sml_op = mop; + mod->sml_type.bv_val = NULL; mod->sml_desc = slap_schema.si_ad_creatorsName; mod->sml_bvalues = (BVarray) ch_malloc( 2 * sizeof( struct berval ) ); ber_dupbv( &mod->sml_bvalues[0], &name ); @@ -629,6 +629,7 @@ int slap_mods_opattrs( mod = (Modifications *) ch_malloc( sizeof( Modifications ) ); mod->sml_op = mop; + mod->sml_type.bv_val = NULL; mod->sml_desc = slap_schema.si_ad_createTimestamp; mod->sml_bvalues = (BVarray) ch_malloc( 2 * sizeof( struct berval ) ); ber_dupbv( &mod->sml_bvalues[0], ×tamp ); @@ -640,6 +641,7 @@ int slap_mods_opattrs( mod = (Modifications *) ch_malloc( sizeof( Modifications ) ); mod->sml_op = mop; + mod->sml_type.bv_val = NULL; mod->sml_desc = slap_schema.si_ad_entryCSN; mod->sml_bvalues = (BVarray) ch_malloc( 2 * sizeof( struct berval ) ); ber_dupbv( &mod->sml_bvalues[0], &csn ); @@ -650,6 +652,7 @@ int slap_mods_opattrs( mod = (Modifications *) ch_malloc( sizeof( Modifications ) ); mod->sml_op = mop; + mod->sml_type.bv_val = NULL; mod->sml_desc = slap_schema.si_ad_modifiersName; mod->sml_bvalues = (BVarray) ch_malloc( 2 * sizeof( struct berval ) ); ber_dupbv( &mod->sml_bvalues[0], &name ); @@ -660,6 +663,7 @@ int slap_mods_opattrs( mod = (Modifications *) ch_malloc( sizeof( Modifications ) ); mod->sml_op = mop; + mod->sml_type.bv_val = NULL; mod->sml_desc = slap_schema.si_ad_modifyTimestamp; mod->sml_bvalues = (BVarray) ch_malloc( 2 * sizeof( struct berval ) ); ber_dupbv( &mod->sml_bvalues[0], ×tamp ); diff --git a/servers/slapd/mods.c b/servers/slapd/mods.c index d9b88aca1c..1aa87afd48 100644 --- a/servers/slapd/mods.c +++ b/servers/slapd/mods.c @@ -24,6 +24,8 @@ slap_mod_free( int freeit ) { + if ( mod->sm_type.bv_val) + free( mod->sm_type.bv_val ); if ( mod->sm_bvalues != NULL ) bvarray_free( mod->sm_bvalues );