Commit 808cb504 authored by Howard Chu's avatar Howard Chu
Browse files

More memory context tweaks

parent ee203dea
...@@ -147,12 +147,14 @@ LDAP_LUNICODE_F(void) ucstr2upper( ...@@ -147,12 +147,14 @@ LDAP_LUNICODE_F(void) ucstr2upper(
LDAP_LUNICODE_F(struct berval *) UTF8bvnormalize( LDAP_LUNICODE_F(struct berval *) UTF8bvnormalize(
struct berval *, struct berval *,
struct berval *, struct berval *,
unsigned ); unsigned,
void *memctx );
LDAP_LUNICODE_F(int) UTF8bvnormcmp( LDAP_LUNICODE_F(int) UTF8bvnormcmp(
struct berval *, struct berval *,
struct berval *, struct berval *,
unsigned ); unsigned,
void *memctx );
LDAP_END_DECL LDAP_END_DECL
......
...@@ -899,14 +899,14 @@ ucdecomp_hangul(unsigned long code, unsigned long *num, unsigned long decomp[]) ...@@ -899,14 +899,14 @@ ucdecomp_hangul(unsigned long code, unsigned long *num, unsigned long decomp[])
/* mode == 0 for canonical, mode == 1 for compatibility */ /* mode == 0 for canonical, mode == 1 for compatibility */
static int static int
uccanoncompatdecomp(const unsigned long *in, int inlen, 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; int l, size;
unsigned i, j, k; unsigned i, j, k;
unsigned long num, class, *decomp, hangdecomp[3]; unsigned long num, class, *decomp, hangdecomp[3];
size = inlen; size = inlen * 2;
*out = (unsigned long *) malloc(size * sizeof(**out)); *out = (unsigned long *) ber_memalloc_x(size * sizeof(**out), ctx);
if (*out == NULL) if (*out == NULL)
return *outlen = -1; return *outlen = -1;
...@@ -915,7 +915,7 @@ uccanoncompatdecomp(const unsigned long *in, int inlen, ...@@ -915,7 +915,7 @@ uccanoncompatdecomp(const unsigned long *in, int inlen,
if (mode ? uckdecomp(in[j], &num, &decomp) : ucdecomp(in[j], &num, &decomp)) { if (mode ? uckdecomp(in[j], &num, &decomp) : ucdecomp(in[j], &num, &decomp)) {
if ( size - i < num) { if ( size - i < num) {
size = inlen + i - j + num - 1; 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) if (*out == NULL)
return *outlen = -1; return *outlen = -1;
} }
...@@ -935,7 +935,7 @@ uccanoncompatdecomp(const unsigned long *in, int inlen, ...@@ -935,7 +935,7 @@ uccanoncompatdecomp(const unsigned long *in, int inlen,
} else if (ucdecomp_hangul(in[j], &num, hangdecomp)) { } else if (ucdecomp_hangul(in[j], &num, hangdecomp)) {
if (size - i < num) { if (size - i < num) {
size = inlen + i - j + num - 1; 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) if (*out == NULL)
return *outlen = -1; return *outlen = -1;
} }
...@@ -946,7 +946,7 @@ uccanoncompatdecomp(const unsigned long *in, int inlen, ...@@ -946,7 +946,7 @@ uccanoncompatdecomp(const unsigned long *in, int inlen,
} else { } else {
if (size - i < 1) { if (size - i < 1) {
size = inlen + i - j; 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) if (*out == NULL)
return *outlen = -1; return *outlen = -1;
} }
...@@ -968,16 +968,16 @@ uccanoncompatdecomp(const unsigned long *in, int inlen, ...@@ -968,16 +968,16 @@ uccanoncompatdecomp(const unsigned long *in, int inlen,
int int
uccanondecomp(const unsigned long *in, int inlen, 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 int
uccompatdecomp(const unsigned long *in, int inlen, 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);
} }
/************************************************************************** /**************************************************************************
......
...@@ -273,7 +273,7 @@ ucdecomp_hangul LDAP_P((unsigned long code, unsigned long *num, ...@@ -273,7 +273,7 @@ ucdecomp_hangul LDAP_P((unsigned long code, unsigned long *num,
*/ */
LDAP_LUNICODE_F (int) LDAP_LUNICODE_F (int)
uccanondecomp LDAP_P((const unsigned long *in, int inlen, 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 * Equivalent to uccanondecomp() except that it includes compatibility
...@@ -281,7 +281,7 @@ uccanondecomp LDAP_P((const unsigned long *in, int inlen, ...@@ -281,7 +281,7 @@ uccanondecomp LDAP_P((const unsigned long *in, int inlen,
*/ */
LDAP_LUNICODE_F (int) LDAP_LUNICODE_F (int)
uccompatdecomp LDAP_P((const unsigned long *in, int inlen, uccompatdecomp LDAP_P((const unsigned long *in, int inlen,
unsigned long **out, int *outlen)); unsigned long **out, int *outlen, void *ctx));
/************************************************************************** /**************************************************************************
* *
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
#include <ldap_utf8.h> #include <ldap_utf8.h>
#include <ldap_pvt_uc.h> #include <ldap_pvt_uc.h>
#define malloc(x) ber_memalloc(x) #define malloc(x) ber_memalloc_x(x,ctx)
#define realloc(x,y) ber_memrealloc(x,y) #define realloc(x,y) ber_memrealloc_x(x,y,ctx)
#define free(x) ber_memfree(x) #define free(x) ber_memfree_x(x,ctx)
int ucstrncmp( int ucstrncmp(
const ldap_unicode_t *u1, const ldap_unicode_t *u1,
...@@ -95,7 +95,8 @@ void ucstr2upper( ...@@ -95,7 +95,8 @@ void ucstr2upper(
struct berval * UTF8bvnormalize( struct berval * UTF8bvnormalize(
struct berval *bv, struct berval *bv,
struct berval *newbv, struct berval *newbv,
unsigned flags ) unsigned flags,
void *ctx )
{ {
int i, j, len, clen, outpos, ucsoutlen, outsize, last; int i, j, len, clen, outpos, ucsoutlen, outsize, last;
char *out, *outtmp, *s; char *out, *outtmp, *s;
...@@ -114,7 +115,7 @@ struct berval * UTF8bvnormalize( ...@@ -114,7 +115,7 @@ struct berval * UTF8bvnormalize(
len = bv->bv_len; len = bv->bv_len;
if ( len == 0 ) { 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 /* FIXME: Should first check to see if string is already in
...@@ -146,7 +147,7 @@ struct berval * UTF8bvnormalize( ...@@ -146,7 +147,7 @@ struct berval * UTF8bvnormalize(
} }
if ( i == len ) { if ( i == len ) {
return ber_str2bv( s, len, 1, newbv ); return ber_str2bv_x( s, len, 1, newbv, ctx );
} }
outsize = len + 7; outsize = len + 7;
...@@ -212,7 +213,7 @@ struct berval * UTF8bvnormalize( ...@@ -212,7 +213,7 @@ struct berval * UTF8bvnormalize(
p++; p++;
} }
/* normalize ucs of length p - ucs */ /* normalize ucs of length p - ucs */
uccompatdecomp( ucs, p - ucs, &ucsout, &ucsoutlen ); uccompatdecomp( ucs, p - ucs, &ucsout, &ucsoutlen, ctx );
if ( approx ) { if ( approx ) {
for ( j = 0; j < ucsoutlen; j++ ) { for ( j = 0; j < ucsoutlen; j++ ) {
if ( ucsout[j] < 0x80 ) { if ( ucsout[j] < 0x80 ) {
...@@ -273,7 +274,8 @@ struct berval * UTF8bvnormalize( ...@@ -273,7 +274,8 @@ struct berval * UTF8bvnormalize(
int UTF8bvnormcmp( int UTF8bvnormcmp(
struct berval *bv1, struct berval *bv1,
struct berval *bv2, struct berval *bv2,
unsigned flags ) unsigned flags,
void *ctx )
{ {
int i, l1, l2, len, ulen, res = 0; int i, l1, l2, len, ulen, res = 0;
char *s1, *s2, *done; char *s1, *s2, *done;
...@@ -376,7 +378,7 @@ int UTF8bvnormcmp( ...@@ -376,7 +378,7 @@ int UTF8bvnormcmp(
return l1 > l2 ? 1 : -1; /* what to do??? */ return l1 > l2 ? 1 : -1; /* what to do??? */
} }
} else { } else {
uccompatdecomp( ucs, ulen, &ucsout1, &l1 ); uccompatdecomp( ucs, ulen, &ucsout1, &l1, ctx );
l1 = uccanoncomp( ucsout1, l1 ); l1 = uccanoncomp( ucsout1, l1 );
} }
...@@ -395,7 +397,7 @@ int UTF8bvnormcmp( ...@@ -395,7 +397,7 @@ int UTF8bvnormcmp(
ucsout2 = ucs; ucsout2 = ucs;
l2 = ulen; l2 = ulen;
} else { } else {
uccompatdecomp( ucs, ulen, &ucsout2, &l2 ); uccompatdecomp( ucs, ulen, &ucsout2, &l2, ctx );
l2 = uccanoncomp( ucsout2, l2 ); l2 = uccanoncomp( ucsout2, l2 );
free( ucs ); free( ucs );
} }
......
...@@ -919,7 +919,7 @@ connection_operation( void *ctx, void *arg_v ) ...@@ -919,7 +919,7 @@ connection_operation( void *ctx, void *arg_v )
memsiz = ber_len( op->o_ber ) * 32; memsiz = ber_len( op->o_ber ) * 32;
if ( SLAB_SIZE > memsiz ) memsiz = SLAB_SIZE; if ( SLAB_SIZE > memsiz ) memsiz = SLAB_SIZE;
if ( tag != LDAP_REQ_ADD ) { if ( tag == LDAP_REQ_SEARCH ) {
memctx = sl_mem_create( memsiz, ctx ); memctx = sl_mem_create( memsiz, ctx );
ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, memctx ); ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, memctx );
op->o_tmpmemctx = memctx; op->o_tmpmemctx = memctx;
......
...@@ -1008,7 +1008,7 @@ UTF8StringNormalize( ...@@ -1008,7 +1008,7 @@ UTF8StringNormalize(
flags |= ( ( use & SLAP_MR_EQUALITY_APPROX ) == SLAP_MR_EQUALITY_APPROX ) flags |= ( ( use & SLAP_MR_EQUALITY_APPROX ) == SLAP_MR_EQUALITY_APPROX )
? LDAP_UTF8_APPROX : 0; ? LDAP_UTF8_APPROX : 0;
val = UTF8bvnormalize( val, &tmp, flags ); val = UTF8bvnormalize( val, &tmp, flags, ctx );
if( val == NULL ) { if( val == NULL ) {
return LDAP_OTHER; return LDAP_OTHER;
} }
......
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