Skip to content

Commit

Permalink
* malloc/malloc.c (_int_realloc): Add parameter with old block
Browse files Browse the repository at this point in the history
	size.  Remove duplicated test.  Don't handle mmap'ed blocks here.
	Adjust all callers.
	* malloc/hooks.c (realloc_check): Adjust _int_realloc call.
  • Loading branch information
Ulrich Drepper committed Apr 8, 2009
1 parent cd57745 commit 4c8b8cc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 22 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2009-04-08 Ulrich Drepper <drepper@redhat.com>

* malloc/malloc.c (_int_realloc): Add parameter with old block
size. Remove duplicated test. Don't handle mmap'ed blocks here.
Adjust all callers.
* malloc/hooks.c (realloc_check): Adjust _int_realloc call.

2009-04-07 Ulrich Drepper <drepper@redhat.com>

* sysdeps/x86_64/strchrnul.S: New file.
Expand Down
26 changes: 23 additions & 3 deletions malloc/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ realloc_check(oldmem, bytes, caller)
if (top_check() >= 0) {
INTERNAL_SIZE_T nb;
checked_request2size(bytes + 1, nb);
newmem = _int_realloc(&main_arena, oldp, nb);
newmem = _int_realloc(&main_arena, oldp, oldsize, nb);
}
#if 0 /* Erase freed memory. */
if(newmem)
Expand Down Expand Up @@ -501,7 +501,7 @@ free_starter(mem, caller) Void_t* mem; const Void_t *caller;
then the hooks are reset to 0. */

#define MALLOC_STATE_MAGIC 0x444c4541l
#define MALLOC_STATE_VERSION (0*0x100l + 3l) /* major*0x100 + minor */
#define MALLOC_STATE_VERSION (0*0x100l + 4l) /* major*0x100 + minor */

struct malloc_save_state {
long magic;
Expand All @@ -521,6 +521,10 @@ struct malloc_save_state {
unsigned long mmapped_mem;
unsigned long max_mmapped_mem;
int using_malloc_checking;
unsigned long max_fast;
unsigned long arena_test;
unsigned long arena_max;
unsigned long narenas;
};

Void_t*
Expand Down Expand Up @@ -568,6 +572,12 @@ public_gET_STATe(void)
ms->mmapped_mem = mp_.mmapped_mem;
ms->max_mmapped_mem = mp_.max_mmapped_mem;
ms->using_malloc_checking = using_malloc_checking;
ms->max_fast = get_max_fast();
#ifdef PER_THREAD
ms->arena_test = mp_.arena_test;
ms->arena_max = mp_.arena_max;
ms->narenas = narenas;
#endif
(void)mutex_unlock(&main_arena.mutex);
return (Void_t*)ms;
}
Expand All @@ -587,7 +597,10 @@ public_sET_STATe(Void_t* msptr)
(void)mutex_lock(&main_arena.mutex);
/* There are no fastchunks. */
clear_fastchunks(&main_arena);
set_max_fast(DEFAULT_MXFAST);
if (ms->version >= 4)
set_max_fast(ms->max_fast);
else
set_max_fast(64); /* 64 used to be the value we always used. */
for (i=0; i<NFASTBINS; ++i)
fastbin (&main_arena, i) = 0;
for (i=0; i<BINMAPSIZE; ++i)
Expand Down Expand Up @@ -663,6 +676,13 @@ public_sET_STATe(Void_t* msptr)
using_malloc_checking = 0;
}
}
if (ms->version >= 4) {
#ifdef PER_THREAD
mp_.arena_test = ms->arena_test;
mp_.arena_max = ms->arena_max;
narenas = ms->narenas;
#endif
}
check_malloc_state(&main_arena);

(void)mutex_unlock(&main_arena.mutex);
Expand Down
33 changes: 17 additions & 16 deletions malloc/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,8 @@ static void _int_free(mstate, mchunkptr, int);
#else
static void _int_free(mstate, mchunkptr);
#endif
static Void_t* _int_realloc(mstate, mchunkptr, INTERNAL_SIZE_T);
static Void_t* _int_realloc(mstate, mchunkptr, INTERNAL_SIZE_T,
INTERNAL_SIZE_T);
static Void_t* _int_memalign(mstate, size_t, size_t);
static Void_t* _int_valloc(mstate, size_t);
static Void_t* _int_pvalloc(mstate, size_t);
Expand Down Expand Up @@ -3778,7 +3779,7 @@ public_rEALLOc(Void_t* oldmem, size_t bytes)
tsd_setspecific(arena_key, (Void_t *)ar_ptr);
#endif

newp = _int_realloc(ar_ptr, oldp, nb);
newp = _int_realloc(ar_ptr, oldp, oldsize, nb);

(void)mutex_unlock(&ar_ptr->mutex);
assert(!newp || chunk_is_mmapped(mem2chunk(newp)) ||
Expand Down Expand Up @@ -5102,7 +5103,8 @@ static void malloc_consolidate(av) mstate av;
*/

Void_t*
_int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T nb)
_int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
INTERNAL_SIZE_T nb)
{
mchunkptr newp; /* chunk to return */
INTERNAL_SIZE_T newsize; /* its size */
Expand All @@ -5123,28 +5125,25 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T nb)

const char *errstr = NULL;

/* Simple tests for old block integrity. */
if (__builtin_expect (misaligned_chunk (oldp), 0))
{
errstr = "realloc(): invalid pointer";
errout:
malloc_printerr (check_action, errstr, chunk2mem(oldp));
return NULL;
}

/* oldmem size */
const INTERNAL_SIZE_T oldsize = chunksize(oldp);

if (__builtin_expect (oldp->size <= 2 * SIZE_SZ, 0)
|| __builtin_expect (oldsize >= av->system_mem, 0))
{
errstr = "realloc(): invalid old size";
goto errout;
errout:
malloc_printerr (check_action, errstr, chunk2mem(oldp));
return NULL;
}

check_inuse_chunk(av, oldp);

if (!chunk_is_mmapped(oldp)) {
/* All callers already filter out mmap'ed chunks. */
#if 0
if (!chunk_is_mmapped(oldp))
#else
assert (!chunk_is_mmapped(oldp));
#endif
{

next = chunk_at_offset(oldp, oldsize);
INTERNAL_SIZE_T nextsize = chunksize(next);
Expand Down Expand Up @@ -5271,6 +5270,7 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T nb)
return chunk2mem(newp);
}

#if 0
/*
Handle mmap cases
*/
Expand Down Expand Up @@ -5339,6 +5339,7 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T nb)
return 0;
#endif
}
#endif
}

/*
Expand Down
2 changes: 1 addition & 1 deletion resolv/res_hconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ _res_hconf_trim_domain (char *hostname)

trim_len = strlen (trim);
if (hostname_len > trim_len
&& strcasecmp (&hostname[hostname_len - trim_len], trim) == 0)
&& __strcasecmp (&hostname[hostname_len - trim_len], trim) == 0)
{
hostname[hostname_len - trim_len] = '\0';
break;
Expand Down
3 changes: 1 addition & 2 deletions sysdeps/x86_64/strchrnul.S
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ ENTRY (__strchrnul)
shl %cl, %esi
pmovmskb %xmm0, %edx
pmovmskb %xmm3, %ecx
andl %esi, %edx
andl %esi, %ecx
orl %edx, %ecx
andl %esi, %ecx
jnz 1f

2: movdqa (%rdi), %xmm0
Expand Down

0 comments on commit 4c8b8cc

Please sign in to comment.