X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Foidm.c;h=24ed7d1b217d0acf3ec978afd3eaf2e82b100497;hb=fb2d3926ce4714b83f76c059a18a0d67d12b8019;hp=99df108cdaaf0585db00cb1999dd48cffa714325;hpb=119cbcaba43185e483b74b359e56fcf5d921404f;p=openldap
diff --git a/servers/slapd/oidm.c b/servers/slapd/oidm.c
index 99df108cda..24ed7d1b21 100644
--- a/servers/slapd/oidm.c
+++ b/servers/slapd/oidm.c
@@ -2,7 +2,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -100,13 +100,14 @@ parse_oidm(
OidMacro **rom)
{
char *oid;
- OidMacro *om;
+ OidMacro *om = NULL;
struct berval bv;
if (argc != 3) {
fprintf( stderr, "%s: line %d: too many arguments\n",
fname, lineno );
usage: fprintf( stderr, "\tObjectIdentifier \n");
+ if (om) SLAP_FREE( om );
return 1;
}
@@ -116,12 +117,13 @@ usage: fprintf( stderr, "\tObjectIdentifier \n");
"%s: line %d: "
"ObjectIdentifier \"%s\" previously defined \"%s\"",
fname, lineno, argv[1], oid );
+ SLAP_FREE( oid );
return 1;
}
- om = (OidMacro *) SLAP_MALLOC( sizeof(OidMacro) );
+ om = (OidMacro *) SLAP_CALLOC( sizeof(OidMacro), 1 );
if( om == NULL ) {
- Debug( LDAP_DEBUG_ANY, "parse_oidm: SLAP_MALLOC failed", 0, 0, 0 );
+ Debug( LDAP_DEBUG_ANY, "parse_oidm: SLAP_CALLOC failed", 0, 0, 0 );
return 1;
}
@@ -156,7 +158,7 @@ void oidm_unparse( BerVarray *res, OidMacro *start, OidMacro *end, int sys )
{
OidMacro *om;
int i, j, num;
- struct berval bv, *bva = NULL, idx;
+ struct berval *bva = NULL, idx;
char ibuf[32], *ptr;
if ( !start )
@@ -164,10 +166,11 @@ void oidm_unparse( BerVarray *res, OidMacro *start, OidMacro *end, int sys )
/* count the result size */
i = 0;
- for ( om=start; om && om!=end; om=LDAP_STAILQ_NEXT(om, som_next)) {
+ for ( om=start; om; om=LDAP_STAILQ_NEXT(om, som_next)) {
if ( sys && !(om->som_flags & SLAP_OM_HARDCODE)) continue;
for ( j=0; !BER_BVISNULL(&om->som_names[j]); j++ );
i += j;
+ if ( om == end ) break;
}
num = i;
if (!i) return;
@@ -179,11 +182,11 @@ void oidm_unparse( BerVarray *res, OidMacro *start, OidMacro *end, int sys )
idx.bv_len = 0;
ibuf[0] = '\0';
}
- for ( i=0,om=start; om && om!=end; om=LDAP_STAILQ_NEXT(om, som_next)) {
+ for ( i=0,om=start; om; om=LDAP_STAILQ_NEXT(om, som_next)) {
if ( sys && !(om->som_flags & SLAP_OM_HARDCODE)) continue;
for ( j=0; !BER_BVISNULL(&om->som_names[j]); i++,j++ ) {
if ( !sys ) {
- idx.bv_len = sprintf(idx.bv_val, "{%02d}", i );
+ idx.bv_len = sprintf(idx.bv_val, "{%d}", i );
}
bva[i].bv_len = idx.bv_len + om->som_names[j].bv_len +
om->som_subs[j].bv_len + 1;
@@ -194,6 +197,7 @@ void oidm_unparse( BerVarray *res, OidMacro *start, OidMacro *end, int sys )
strcpy( ptr, om->som_subs[j].bv_val );
}
if ( i>=num ) break;
+ if ( om == end ) break;
}
*res = bva;
}