mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-01-04 14:10:39 -05:00
More memory context tweaks
This commit is contained in:
parent
ee203deadf
commit
808cb504ce
6 changed files with 30 additions and 26 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@
|
|||
#include <ldap_utf8.h>
|
||||
#include <ldap_pvt_uc.h>
|
||||
|
||||
#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 );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue