Introduction of ldbm_datum_init().
Patch for non-NULL pointer test befor call to ldbm_datum_free().
Datum ldbm_nextkey( LDBM ldbm, Datum key );
#endif
+
+/* initialization of Datum structures */
+#ifdef HAVE_BERKELEY_DB2
+
+# define ldbm_datum_init(d) ((void)memset(&(d), 0, sizeof(Datum)))
+
+#else
+
+# define ldbm_datum_init(d) ((void)0)
+
+#endif /* HAVE_BERKELEY_DB2 */
+
#endif /* _ldbm_h_ */
dbinfo.db_pagesize = DEFAULT_DB_PAGE_SIZE;
dbinfo.db_malloc = ldbm_malloc;
- db_open( name, DB_TYPE, rw, mode, NULL, &dbinfo, &ret );
+ (void) db_open( name, DB_TYPE, rw, mode, NULL, &dbinfo, &ret );
#else
void *info;
{
Datum dup;
-#ifdef HAVE_BERKELEY_DB2
- memset( &dup, 0, sizeof( dup ));
-#endif
+ ldbm_datum_init( dup );
if ( data.dsize == 0 ) {
- dup.dsize = 0;
- dup.dptr = NULL;
-
return( dup );
}
dup.dsize = data.dsize;
int rc;
#ifdef HAVE_BERKELEY_DB2
- memset( &data, 0, sizeof( data ));
+ ldbm_datum_init( data );
data.flags = DB_DBT_MALLOC;
#else
rc = (*ldbm->put)( ldbm, &key, &data, flags & ~LDBM_SYNC );
#endif
+
if ( flags & LDBM_SYNC )
(*ldbm->sync)( ldbm, 0 );
return( rc );
#ifdef HAVE_BERKELEY_DB2
DBC *dbci;
- memset( &key, 0, sizeof( key ));
- memset( &data, 0, sizeof( data ));
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
key.flags = data.flags = DB_DBT_MALLOC;
/* acquire a cursor for the DB */
+
+# if defined( DB_VERSION_MAJOR ) && defined( DB_VERSION_MINOR ) && \
+ DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR < 6
+
if ( (*ldbm->cursor)( ldbm, NULL, &dbci )) {
+
+# else
+
+ if ( (*ldbm->cursor)( ldbm, NULL, &dbci, 0 )) {
+
+# endif
+
return( key );
} else {
*dbch = dbci;
#ifdef HAVE_BERKELEY_DB2
void *oldKey = key.dptr;
- memset( &data, 0, sizeof( data ));
+ ldbm_datum_init( data );
data.flags = DB_DBT_MALLOC;
/*****************************************************************
* *
- * use gdbm *
+ * use gdbm *
* *
*****************************************************************/
)
{
Datum data;
-#ifdef HAVE_BERKELEY_DB2
- memset( &data, 0, sizeof( data ) );
-#endif
+
+ ldbm_datum_init( data );
pthread_mutex_lock( &db->dbc_mutex );
#ifdef reentrant_database
Datum key, data;
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
-#ifdef HAVE_BERKELEY_DB2
- memset( &key, 0, sizeof( key ) );
- memset( &data, 0, sizeof( data ) );
-#endif
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
Debug( LDAP_DEBUG_TRACE, "=> dn2id_add( \"%s\", %ld )\n", dn, id, 0 );
ID id;
Datum key, data;
-#ifdef HAVE_BERKELEY_DB2
- memset( &key, 0, sizeof( key ) );
- memset( &data, 0, sizeof( data ) );
-#endif
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
dn = ch_strdup( dn );
Debug( LDAP_DEBUG_TRACE, "=> dn2id( \"%s\" )\n", dn, 0, 0 );
Datum key;
int rc;
-#ifdef HAVE_BERKELEY_DB2
- memset( &key, 0, sizeof( key ) );
-#endif
+ ldbm_datum_init( key );
Debug( LDAP_DEBUG_TRACE, "=> dn2id_delete( \"%s\" )\n", dn, 0, 0 );
#ifdef HAVE_BERKELEY_DB2
Datum data;
- memset( &key, 0, sizeof( key ) );
- memset( &data, 0, sizeof( data ) );
+
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
#endif
Debug( LDAP_DEBUG_TRACE, "=> id2children_add( %lu, %lu )\n",
return( -1 );
}
- memset( &key, 0, sizeof(key) );
+ ldbm_datum_init( key );
sprintf( buf, "%c%ld", EQ_PREFIX, p ? p->e_id : 0 );
key.dptr = buf;
key.dsize = strlen( buf ) + 1;
IDList *idl;
char buf[20];
-#ifdef HAVE_BERKELEY_DB2
- memset( &key, 0, sizeof( key ) );
-#endif
+ ldbm_datum_init( key );
Debug( LDAP_DEBUG_TRACE, "=> has_children( %lu )\n", p->e_id , 0, 0 );
Datum key, data;
int len, rc, flags;
-#ifdef HAVE_BERKELEY_DB2
- memset( &key, 0, sizeof( key ) );
- memset( &data, 0, sizeof( data ) );
-#endif
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
Debug( LDAP_DEBUG_TRACE, "=> id2entry_add( %lu, \"%s\" )\n", e->e_id,
e->e_dn, 0 );
assert(pthread_rdwr_wchk_np(&e->e_rdwr));
#endif
-#ifdef HAVE_BERKELEY_DB2
- memset( &key, 0, sizeof( key ) );
-#endif
+ ldbm_datum_init( key );
/* XXX - check for writer lock - should also check no reader pending */
Debug (LDAP_DEBUG_TRACE,
Datum key, data;
Entry *e;
-#ifdef HAVE_BERKELEY_DB2
- memset( &key, 0, sizeof( key ) );
- memset( &data, 0, sizeof( data ) );
-#endif
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
Debug( LDAP_DEBUG_TRACE, "=> id2entry_%s( %ld )\n",
rw ? "w" : "r", id, 0 );
#ifdef HAVE_BERKELEY_DB2
Datum k2;
- memset( &k2, 0, sizeof( k2 ) );
- memset( &data, 0, sizeof( data ) );
+
+ ldbm_datum_init( data );
+ ldbm_datum_init( k2 );
#endif
/* Debug( LDAP_DEBUG_TRACE, "=> idl_fetch_one\n", 0, 0, 0 ); */
char *kstr;
int i, nids;
-#ifdef HAVE_BERKELEY_DB2
- memset( &k2, 0, sizeof( k2 ) );
- memset( &data, 0, sizeof( data ) );
-#endif
+ ldbm_datum_init( k2 );
+ ldbm_datum_init( data );
/* Debug( LDAP_DEBUG_TRACE, "=> idl_fetch\n", 0, 0, 0 ); */
Datum data;
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
-#ifdef HAVE_BERKELEY_DB2
- memset( &data, 0, sizeof( data ) );
-#endif
+ ldbm_datum_init( data );
/* Debug( LDAP_DEBUG_TRACE, "=> idl_store\n", 0, 0, 0 ); */
char *kstr;
Datum k2;
-#ifdef HAVE_BERKELEY_DB2
- memset( &k2, 0, sizeof( k2 ) );
-#endif
+ ldbm_datum_init( k2 );
if ( (idl = idl_fetch_one( be, db, key )) == NULL ) {
#ifdef LDBM_DEBUG
kstr = (char *) ch_malloc( key.dsize + 20 );
for ( j = 0; idl->b_ids[j] != NOID; j++ )
{
- memset( &k2, 0, sizeof(k2) );
+ ldbm_datum_init( k2 );
sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, idl->b_ids[j] );
k2.dptr = kstr;
k2.dsize = strlen( kstr ) + 1;
char *realval, *tmpval;
char buf[BUFSIZ];
-#ifdef HAVE_BERKELEY_DB2
- memset( &key, 0, sizeof( key ) );
-#endif
+ ldbm_datum_init( key );
prefix = index2prefix( indextype );
Debug( LDAP_DEBUG_TRACE, "=> index_read( \"%s\" \"%c\" \"%s\" )\n",
char *realval, *tmpval, *s;
char buf[BUFSIZ];
-#ifdef HAVE_BERKELEY_DB2
- memset( &key, 0, sizeof( key ) );
-#endif
+ ldbm_datum_init( key );
prefix = index2prefix( indextype );
Debug( LDAP_DEBUG_TRACE, "=> add_value( \"%c%s\" )\n", prefix, val, 0 );
char **val;
char last;
- memset( &data, 0 , sizeof( data ));
+ ldbm_datum_init( data );
if ( verbose ) {
printf( "Generating new centroids for..." );
/* for each value */
for ( j = 0; val[j] != NULL; j++ ) {
- memset( &key, 0 , sizeof( key ));
+ ldbm_datum_init( key );
/* normalize the value */
for ( s = val[j]; *s; s++ ) {
fflush( stdout );
}
- memset( &okey, 0, sizeof( okey ));
- memset( &nkey, 0, sizeof( nkey ));
- memset( &olast, 0, sizeof( olast ));
- memset( &nlast, 0, sizeof( nlast ));
- memset( &lastkey, 0, sizeof( lastkey ));
- memset( &key, 0, sizeof( key ));
- memset( &data, 0, sizeof( data ));
+ ldbm_datum_init( okey );
+ ldbm_datum_init( nkey );
+ ldbm_datum_init( olast );
+ ldbm_datum_init( nlast );
+ ldbm_datum_init( lastkey );
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
if ( (mods = (LDAPMod **) malloc( sizeof(LDAPMod *) * 4 )) == NULL ||
(mods[0] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL ||
fflush( stdout );
}
- memset( &key, 0, sizeof( key ));
- memset( &lastkey, 0, sizeof( lastkey ));
+ ldbm_datum_init( key );
+ ldbm_datum_init( lastkey );
if ( (mods = (LDAPMod **) malloc( sizeof(LDAPMod *) * 3 )) == NULL ||
(mods[0] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL ||
static void
usage( char *name )
{
- fprintf( stderr, "usage: %s [-n] <filename>\n", name );
- exit( 1 );
+ fprintf( stderr, "usage: %s [-n] <filename>\n", name );
+ exit( 1 );
}
int
main( int argc, char **argv )
{
- Datum key, last, data;
- LDBM dbp;
- int rc, type;
- long id;
- char *file, *s;
- int printid = 1;
+ Datum key, last, data;
+ LDBM dbp;
+ int rc, type;
+ long id;
+ char *file, *s;
+ int printid = 1;
#ifdef HAVE_BERKELEY_DB2
- DBC *cursorp;
+ DBC *cursorp;
- memset( &key, 0, sizeof( key ));
- memset( &last, 0, sizeof( last ));
- memset( &data, 0, sizeof( data ));
+ ldbm_datum_init( key );
+ ldbm_datum_init( last );
+ ldbm_datum_init( data );
#endif
- if ( argc < 2 || argc > 3 || ( argc == 3 && strcmp( argv[1], "-n" )
- != 0 )) {
- usage( argv[0] );
- }
- if ( argc == 3 && strcmp( argv[1], "-n" ) == 0 ) {
- printid = 0;
- file = argv[2];
- } else {
- file = argv[1];
- }
-
- if ( (dbp = ldbm_open( file, LDBM_READER, 0, 0 )) == NULL ) {
- perror( file );
- exit ( 1 );
- }
+ if ( argc < 2 || argc > 3 || ( argc == 3 && strcmp( argv[1], "-n" )
+ != 0 )) {
+ usage( argv[0] );
+ }
+ if ( argc == 3 && strcmp( argv[1], "-n" ) == 0 ) {
+ printid = 0;
+ file = argv[2];
+ } else {
+ file = argv[1];
+ }
+
+ if ( (dbp = ldbm_open( file, LDBM_READER, 0, 0 )) == NULL ) {
+ perror( file );
+ exit ( 1 );
+ }
last.dptr = NULL;
for ( key = ldbm_firstkey( dbp ); key.dptr != NULL;
key = ldbm_nextkey( dbp, last ) )
#endif
- {
+ {
if ( last.dptr != NULL )
ldbm_datum_free( dbp, last );
data = ldbm_fetch( dbp, key );
- s = data.dptr;
- if ( !printid && isdigit( *s )) {
- if (( s = strchr( s, '\n' )) != NULL ) {
- ++s;
- }
- }
- if ( s != NULL ) {
- puts( s );
- }
- ldbm_datum_free( dbp, data );
+
+ if (( s = data.dptr ) != NULL ) {
+
+ if ( !printid && isdigit( *s )) {
+ if (( s = strchr( s, '\n' )) != NULL ) {
+ ++s;
+ }
+ }
+ if ( s != NULL ) {
+ puts( s );
+ }
+
+ if ( data.dptr != NULL ) {
+ ldbm_datum_free( dbp, data );
+ }
+
+ }
+
last = key;
}
if ( last.dptr != NULL )
ldbm_datum_free( dbp, last );
- ldbm_close( dbp );
+ ldbm_close( dbp );
- exit( 0 );
+ exit( 0 );
}
#ifdef HAVE_BERKELEY_DB2
DBC *cursorp;
- memset( &savekey, 0, sizeof( savekey ));
- memset( &key, 0, sizeof( key ));
- memset( &data, 0, sizeof( data ));
- memset( &last, 0, sizeof( last ));
+ ldbm_datum_init( savekey );
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
+ ldbm_datum_init( last );
#endif
tailorfile = SLAPD_DEFAULT_CONFIGFILE;
"key: ", NULL, NULL );
}
- ldbm_datum_free( dbc->dbc_db, data );
+ if ( data.dptr != NULL ) {
+ ldbm_datum_free( dbc->dbc_db, data );
+ }
}
if ( savekey.dptr != NULL )
ldbm_datum_free( dbc->dbc_db, savekey );
perror( tmpname );
return;
}
- ldbm_datum_free( NULL, *data );
+ if ( data->dptr != NULL ) {
+ ldbm_datum_free( NULL, *data );
+ }
get_keydata( fp, c, NULL, data );
fclose( fp );
unlink( tmpname );
int vlen;
Datum key, data;
- memset( &key, 0, sizeof( key ));
- memset( &data, 0, sizeof( data ));
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
if ( fgets( line, sizeof(line), stdin ) != NULL ) {
int len;
char buf2[20];
Datum key, data;
- memset( &key, 0, sizeof( key ));
- memset( &data, 0, sizeof( data ));
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
if ( fgets( line, sizeof(line), stdin ) != NULL ) {
int len;
int vlen;
Datum key, data;
- memset( &key, 0, sizeof( key ));
- memset( &data, 0, sizeof( data ));
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
if ( fgets( line, sizeof(line), stdin ) != NULL ) {
int len, idlen;
int vlen, indexmask, syntaxmask;
Datum key, data;
- memset( &key, 0, sizeof( key ));
- memset( &data, 0, sizeof( data ));
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
if ( fgets( line, sizeof(line), stdin ) != NULL ) {
int len;
Datum key, data;
char *w;
- memset( &key, 0, sizeof( key ));
- memset( &data, 0, sizeof( data ));
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
/* update value count */
vcount++;
{
Datum key, data;
- memset( &key, 0, sizeof( key ));
- memset( &data, 0, sizeof( data ));
+ ldbm_datum_init( key );
+ ldbm_datum_init( data );
key.dptr = s;
key.dsize = strlen( key.dptr ) + 1;
(*count)++;
(*size) += strlen( key.dptr );
}
- if ( freeit )
+ if ( freeit && ( key.dptr != NULL ) )
ldbm_datum_free( ldbm, key );
}