From 808cb504cecb44124b16e7b9284145f176e97985 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 11 Apr 2003 03:57:10 +0000 Subject: [PATCH] More memory context tweaks --- include/ldap_pvt_uc.h | 6 ++++-- libraries/liblunicode/ucdata/ucdata.c | 20 ++++++++++---------- libraries/liblunicode/ucdata/ucdata.h | 4 ++-- libraries/liblunicode/ucstr.c | 22 ++++++++++++---------- servers/slapd/connection.c | 2 +- servers/slapd/schema_init.c | 2 +- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/include/ldap_pvt_uc.h b/include/ldap_pvt_uc.h index cffebaa47c..c8c2cde746 100644 --- a/include/ldap_pvt_uc.h +++ b/include/ldap_pvt_uc.h @@ -147,12 +147,14 @@ LDAP_LUNICODE_F(void) ucstr2upper( LDAP_LUNICODE_F(struct berval *) UTF8bvnormalize( struct berval *, struct berval *, - unsigned ); + unsigned, + void *memctx ); LDAP_LUNICODE_F(int) UTF8bvnormcmp( struct berval *, struct berval *, - unsigned ); + unsigned, + void *memctx ); LDAP_END_DECL diff --git a/libraries/liblunicode/ucdata/ucdata.c b/libraries/liblunicode/ucdata/ucdata.c index f67358ec74..e90758641c 100644 --- a/libraries/liblunicode/ucdata/ucdata.c +++ b/libraries/liblunicode/ucdata/ucdata.c @@ -899,14 +899,14 @@ ucdecomp_hangul(unsigned long code, unsigned long *num, unsigned long decomp[]) /* mode == 0 for canonical, mode == 1 for compatibility */ static int uccanoncompatdecomp(const unsigned long *in, int inlen, - unsigned long **out, int *outlen, short mode) + unsigned long **out, int *outlen, short mode, void *ctx) { int l, size; unsigned i, j, k; unsigned long num, class, *decomp, hangdecomp[3]; - size = inlen; - *out = (unsigned long *) malloc(size * sizeof(**out)); + size = inlen * 2; + *out = (unsigned long *) ber_memalloc_x(size * sizeof(**out), ctx); if (*out == NULL) return *outlen = -1; @@ -915,7 +915,7 @@ uccanoncompatdecomp(const unsigned long *in, int inlen, if (mode ? uckdecomp(in[j], &num, &decomp) : ucdecomp(in[j], &num, &decomp)) { if ( size - i < num) { size = inlen + i - j + num - 1; - *out = (unsigned long *) realloc(*out, size * sizeof(**out)); + *out = (unsigned long *) ber_memrealloc_x(*out, size * sizeof(**out), ctx ); if (*out == NULL) return *outlen = -1; } @@ -935,7 +935,7 @@ uccanoncompatdecomp(const unsigned long *in, int inlen, } else if (ucdecomp_hangul(in[j], &num, hangdecomp)) { if (size - i < num) { size = inlen + i - j + num - 1; - *out = (unsigned long *) realloc(*out, size * sizeof(**out)); + *out = (unsigned long *) ber_memrealloc_x(*out, size * sizeof(**out), ctx); if (*out == NULL) return *outlen = -1; } @@ -946,7 +946,7 @@ uccanoncompatdecomp(const unsigned long *in, int inlen, } else { if (size - i < 1) { size = inlen + i - j; - *out = (unsigned long *) realloc(*out, size * sizeof(**out)); + *out = (unsigned long *) ber_memrealloc_x(*out, size * sizeof(**out), ctx); if (*out == NULL) return *outlen = -1; } @@ -968,16 +968,16 @@ uccanoncompatdecomp(const unsigned long *in, int inlen, int uccanondecomp(const unsigned long *in, int inlen, - unsigned long **out, int *outlen) + unsigned long **out, int *outlen, void *ctx) { - return uccanoncompatdecomp(in, inlen, out, outlen, 0); + return uccanoncompatdecomp(in, inlen, out, outlen, 0, ctx); } int uccompatdecomp(const unsigned long *in, int inlen, - unsigned long **out, int *outlen) + unsigned long **out, int *outlen, void *ctx) { - return uccanoncompatdecomp(in, inlen, out, outlen, 1); + return uccanoncompatdecomp(in, inlen, out, outlen, 1, ctx); } /************************************************************************** diff --git a/libraries/liblunicode/ucdata/ucdata.h b/libraries/liblunicode/ucdata/ucdata.h index 9b50178053..0fbe3a3271 100644 --- a/libraries/liblunicode/ucdata/ucdata.h +++ b/libraries/liblunicode/ucdata/ucdata.h @@ -273,7 +273,7 @@ ucdecomp_hangul LDAP_P((unsigned long code, unsigned long *num, */ LDAP_LUNICODE_F (int) uccanondecomp LDAP_P((const unsigned long *in, int inlen, - unsigned long **out, int *outlen)); + unsigned long **out, int *outlen, void *ctx)); /* * Equivalent to uccanondecomp() except that it includes compatibility @@ -281,7 +281,7 @@ uccanondecomp LDAP_P((const unsigned long *in, int inlen, */ LDAP_LUNICODE_F (int) uccompatdecomp LDAP_P((const unsigned long *in, int inlen, - unsigned long **out, int *outlen)); + unsigned long **out, int *outlen, void *ctx)); /************************************************************************** * diff --git a/libraries/liblunicode/ucstr.c b/libraries/liblunicode/ucstr.c index e6060156b5..53b1ed349f 100644 --- a/libraries/liblunicode/ucstr.c +++ b/libraries/liblunicode/ucstr.c @@ -15,9 +15,9 @@ #include #include -#define malloc(x) ber_memalloc(x) -#define realloc(x,y) ber_memrealloc(x,y) -#define free(x) ber_memfree(x) +#define malloc(x) ber_memalloc_x(x,ctx) +#define realloc(x,y) ber_memrealloc_x(x,y,ctx) +#define free(x) ber_memfree_x(x,ctx) int ucstrncmp( const ldap_unicode_t *u1, @@ -95,7 +95,8 @@ void ucstr2upper( struct berval * UTF8bvnormalize( struct berval *bv, struct berval *newbv, - unsigned flags ) + unsigned flags, + void *ctx ) { int i, j, len, clen, outpos, ucsoutlen, outsize, last; char *out, *outtmp, *s; @@ -114,7 +115,7 @@ struct berval * UTF8bvnormalize( len = bv->bv_len; if ( len == 0 ) { - return ber_dupbv( newbv, bv ); + return ber_dupbv_x( newbv, bv, ctx ); } /* FIXME: Should first check to see if string is already in @@ -146,7 +147,7 @@ struct berval * UTF8bvnormalize( } if ( i == len ) { - return ber_str2bv( s, len, 1, newbv ); + return ber_str2bv_x( s, len, 1, newbv, ctx ); } outsize = len + 7; @@ -212,7 +213,7 @@ struct berval * UTF8bvnormalize( p++; } /* normalize ucs of length p - ucs */ - uccompatdecomp( ucs, p - ucs, &ucsout, &ucsoutlen ); + uccompatdecomp( ucs, p - ucs, &ucsout, &ucsoutlen, ctx ); if ( approx ) { for ( j = 0; j < ucsoutlen; j++ ) { if ( ucsout[j] < 0x80 ) { @@ -273,7 +274,8 @@ struct berval * UTF8bvnormalize( int UTF8bvnormcmp( struct berval *bv1, struct berval *bv2, - unsigned flags ) + unsigned flags, + void *ctx ) { int i, l1, l2, len, ulen, res = 0; char *s1, *s2, *done; @@ -376,7 +378,7 @@ int UTF8bvnormcmp( return l1 > l2 ? 1 : -1; /* what to do??? */ } } else { - uccompatdecomp( ucs, ulen, &ucsout1, &l1 ); + uccompatdecomp( ucs, ulen, &ucsout1, &l1, ctx ); l1 = uccanoncomp( ucsout1, l1 ); } @@ -395,7 +397,7 @@ int UTF8bvnormcmp( ucsout2 = ucs; l2 = ulen; } else { - uccompatdecomp( ucs, ulen, &ucsout2, &l2 ); + uccompatdecomp( ucs, ulen, &ucsout2, &l2, ctx ); l2 = uccanoncomp( ucsout2, l2 ); free( ucs ); } diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 67ec8daea8..09410a3f27 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -919,7 +919,7 @@ connection_operation( void *ctx, void *arg_v ) memsiz = ber_len( op->o_ber ) * 32; if ( SLAB_SIZE > memsiz ) memsiz = SLAB_SIZE; - if ( tag != LDAP_REQ_ADD ) { + if ( tag == LDAP_REQ_SEARCH ) { memctx = sl_mem_create( memsiz, ctx ); ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, memctx ); op->o_tmpmemctx = memctx; diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 60c14a89a8..682d8e4902 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -1008,7 +1008,7 @@ UTF8StringNormalize( flags |= ( ( use & SLAP_MR_EQUALITY_APPROX ) == SLAP_MR_EQUALITY_APPROX ) ? LDAP_UTF8_APPROX : 0; - val = UTF8bvnormalize( val, &tmp, flags ); + val = UTF8bvnormalize( val, &tmp, flags, ctx ); if( val == NULL ) { return LDAP_OTHER; } -- 2.39.5