From ce6243f0099b283bc298dad807be38e53020e274 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 19 Oct 2001 20:28:48 +0000 Subject: [PATCH] Patches for modify/modrdn to work with BDB_USE_BINARY_RW. --- servers/slapd/back-bdb/id2entry.c | 15 +++++++++++++-- servers/slapd/back-bdb/modify.c | 3 +++ servers/slapd/back-bdb/modrdn.c | 9 +++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/servers/slapd/back-bdb/id2entry.c b/servers/slapd/back-bdb/id2entry.c index 688cdc4e9d..538249eb34 100644 --- a/servers/slapd/back-bdb/id2entry.c +++ b/servers/slapd/back-bdb/id2entry.c @@ -156,7 +156,11 @@ int bdb_encode(Entry *e, struct berval **bv) /* Retrieve an Entry that was stored using bdb_encode above. * All we have to do is add the buffer address to all of the * stored offsets. We also use the stored attribute names to - * pull AttributeDescriptions from our ad_cache. + * pull AttributeDescriptions from our ad_cache. To detect if + * the attributes of an Entry are later modified, we also store + * the address of the end of this block in e_private. Since + * modify_internal always allocs a new list of attrs to work + * with, we need to free that separately. */ int bdb_decode(struct berval *bv, Entry **e) { @@ -192,7 +196,6 @@ int bdb_decode(struct berval *bv, Entry **e) #define entry_encode(a, b) bdb_encode(a,b) #define entry_decode(a, b) bdb_decode(a,b) -#define entry_free(e) ch_free(e) #endif /* BDB_USE_BINARY_RW */ @@ -321,6 +324,14 @@ int bdb_entry_return( BackendDB *be, Entry *e ) { +#ifdef BDB_USE_BINARY_RW + /* bdb_modify_internal always operates on a dup'd set of attrs. */ + if ((void *)e->e_attrs < (void *)e || + (void *)e->e_attrs > e->e_private) + attrs_free(e->e_attrs); + ch_free(e); +#else entry_free( e ); +#endif return 0; } diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 4076ff48d3..279a8776a1 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -147,7 +147,10 @@ int bdb_modify_internal( return rc; } +#ifndef BDB_USE_BINARY_RW + /* cannot free individual elements of the entry */ attrs_free( save_attrs ); +#endif return rc; } diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index 24522e17e1..3da231e231 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -480,12 +480,21 @@ retry: /* transaction retry */ goto return_results; } +#ifdef BDB_USE_BINARY_RW + /* Binary format uses a single contiguous block, cannot + * free individual fields. Leave new_dn/new_ndn set so + * they can be individually freed later. + */ + e->e_dn = new_dn; + e->e_ndn = new_ndn; +#else free( e->e_dn ); free( e->e_ndn ); e->e_dn = new_dn; e->e_ndn = new_ndn; new_dn = NULL; new_ndn = NULL; +#endif /* add new one */ rc = bdb_dn2id_add( be, ltid, e->e_ndn, e->e_id ); -- 2.39.5