]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/id2entry.c
Merge branch 'mdb.master' of /home/hyc/OD/mdb
[openldap] / servers / slapd / back-bdb / id2entry.c
index 416c9fed7a003a2e6c58f60e49a109cb26a6ebbf..51238a151a68512db174c0a46fc82a4d9f6ee0ff 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2008 The OpenLDAP Foundation.
+ * Copyright 2000-2011 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -131,24 +131,26 @@ int bdb_id2entry(
        rc = entry_header( &eh );
        if ( rc ) goto finish;
 
-       /* Get the size */
-       data.flags ^= DB_DBT_PARTIAL;
-       data.ulen = 0;
-       rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
-       if ( rc != DB_BUFFER_SMALL ) goto finish;
-
-       /* Allocate a block and retrieve the data */
-       off = eh.data - eh.bv.bv_val;
-       eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + data.size;
-       eh.bv.bv_val = ch_malloc( eh.bv.bv_len );
-       eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval );
-       data.data = eh.data;
-       data.ulen = data.size;
-
-       /* skip past already parsed nattr/nvals */
-       eh.data += off;
-
-       rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
+       if ( eh.nvals ) {
+               /* Get the size */
+               data.flags ^= DB_DBT_PARTIAL;
+               data.ulen = 0;
+               rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
+               if ( rc != DB_BUFFER_SMALL ) goto finish;
+
+               /* Allocate a block and retrieve the data */
+               off = eh.data - eh.bv.bv_val;
+               eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + data.size;
+               eh.bv.bv_val = ch_malloc( eh.bv.bv_len );
+               eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval );
+               data.data = eh.data;
+               data.ulen = data.size;
+
+               /* skip past already parsed nattr/nvals */
+               eh.data += off;
+
+               rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
+       }
 
 finish:
        cursor->c_close( cursor );
@@ -157,11 +159,15 @@ finish:
                return rc;
        }
 
+       if ( eh.nvals ) {
 #ifdef SLAP_ZONE_ALLOC
-       rc = entry_decode(&eh, e, bdb->bi_cache.c_zctx);
+               rc = entry_decode(&eh, e, bdb->bi_cache.c_zctx);
 #else
-       rc = entry_decode(&eh, e);
+               rc = entry_decode(&eh, e);
 #endif
+       } else {
+               *e = entry_alloc();
+       }
 
        if( rc == 0 ) {
                (*e)->e_id = id;
@@ -422,7 +428,7 @@ return_results:
                                                op->o_tmpmemctx );
                                        bli->bli_next = boi->boi_locks;
                                        bli->bli_id = e->e_id;
-                                       bii->bli_flag = 0;
+                                       bli->bli_flag = 0;
                                        bli->bli_lock = lock;
                                        boi->boi_locks = bli;
                                }