From ee98e6938c19247f3c3b2bfb04bdf77f254c8e0d Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 2 Jan 2002 12:34:35 +0000 Subject: [PATCH] Fix memory leak of Mod.sml_type --- servers/slapd/add.c | 7 ++----- servers/slapd/modify.c | 14 +++++++++----- servers/slapd/mods.c | 2 ++ 3 files changed, 13 insertions(+), 10 deletions(-) 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 ); -- 2.39.5