Commit cd0a65df authored by Howard Chu's avatar Howard Chu
Browse files

ITS#2348: cleanup cont_alloc/cont_free in idl_insert_key

parent cb19db7e
...@@ -534,14 +534,12 @@ idl_insert_key( ...@@ -534,14 +534,12 @@ idl_insert_key(
/* is there a next block? */ /* is there a next block? */
if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) { if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) {
/* read it in */ /* read it in */
cont_alloc( &k2, &key );
cont_id( &k2, ID_BLOCK_ID(idl, i + 1) ); cont_id( &k2, ID_BLOCK_ID(idl, i + 1) );
if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) { if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) {
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"idl_insert_key: idl_fetch_one returned NULL\n", "idl_insert_key: idl_fetch_one returned NULL\n",
0, 0, 0 ); 0, 0, 0 );
/* split the original block */ /* split the original block */
cont_free( &k2 );
goto split; goto split;
} }
...@@ -552,9 +550,6 @@ idl_insert_key( ...@@ -552,9 +550,6 @@ idl_insert_key(
*/ */
if (id < ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp) - 1)) { if (id < ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp) - 1)) {
ID id2 = ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp) - 1); ID id2 = ID_BLOCK_ID(tmp, ID_BLOCK_NIDS(tmp) - 1);
Datum k3;
ldbm_datum_init( k3 );
--ID_BLOCK_NIDS(tmp); --ID_BLOCK_NIDS(tmp);
/* This must succeed since we just popped one /* This must succeed since we just popped one
...@@ -562,16 +557,11 @@ idl_insert_key( ...@@ -562,16 +557,11 @@ idl_insert_key(
*/ */
rc = idl_insert( &tmp, id, db->dbc_maxids ); rc = idl_insert( &tmp, id, db->dbc_maxids );
k3.dptr = ch_malloc(k2.dsize); if ( (rc = idl_store( be, db, k2, tmp )) != 0 ) {
k3.dsize = k2.dsize;
AC_MEMCPY(k3.dptr, k2.dptr, k3.dsize);
if ( (rc = idl_store( be, db, k3, tmp )) != 0 ) {
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"idl_insert_key: idl_store returned %d\n", rc, 0, 0 ); "idl_insert_key: idl_store returned %d\n", rc, 0, 0 );
} }
free( k3.dptr );
id = id2; id = id2;
/* This new id will necessarily be inserted /* This new id will necessarily be inserted
* as the first id of the next block by the * as the first id of the next block by the
...@@ -600,6 +590,7 @@ idl_insert_key( ...@@ -600,6 +590,7 @@ idl_insert_key(
idl_free( tmp ); idl_free( tmp );
idl_free( tmp2 ); idl_free( tmp2 );
cont_free( &k2 );
idl_free( idl ); idl_free( idl );
return( 0 ); return( 0 );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment