|
From: <sv...@va...> - 2005-10-06 09:07:04
|
Author: tom
Date: 2005-10-06 10:06:59 +0100 (Thu, 06 Oct 2005)
New Revision: 4876
Log:
Merge realloc fixes from trunk to stable branch.
Modified:
branches/VALGRIND_3_0_BRANCH/helgrind/hg_main.c
branches/VALGRIND_3_0_BRANCH/massif/ms_main.c
branches/VALGRIND_3_0_BRANCH/memcheck/mac_malloc_wrappers.c
Modified: branches/VALGRIND_3_0_BRANCH/helgrind/hg_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/VALGRIND_3_0_BRANCH/helgrind/hg_main.c 2005-10-06 09:00:17 U=
TC (rev 4875)
+++ branches/VALGRIND_3_0_BRANCH/helgrind/hg_main.c 2005-10-06 09:06:59 U=
TC (rev 4876)
@@ -1964,7 +1964,6 @@
{
HG_Chunk *hc;
HG_Chunk **prev_chunks_next_ptr;
- Int i;
=20
/* First try and find the block. */
hc =3D (HG_Chunk*)VG_(HT_get_node) ( hg_malloc_list, (UWord)p,
@@ -1992,22 +1991,23 @@
/* Get new memory */
p_new =3D (Addr)VG_(cli_malloc)(VG_(clo_alignment), new_size);
=20
- /* First half kept and copied, second half new */
- copy_address_range_state( (Addr)p, p_new, hc->size );
- hg_new_mem_heap ( p_new+hc->size, new_size-hc->size,
- /*inited*/False );
+ if (p_new) {
+ /* First half kept and copied, second half new */
+ copy_address_range_state( (Addr)p, p_new, hc->size );
+ hg_new_mem_heap ( p_new+hc->size, new_size-hc->size,
+ /*inited*/False );
=20
- /* Copy from old to new */
- for (i =3D 0; i < hc->size; i++)
- ((UChar*)p_new)[i] =3D ((UChar*)p)[i];
+ /* Copy from old to new */
+ VG_(memcpy)((void *)p_new, p, hc->size);
=20
- /* Free old memory */
- die_and_free_mem ( tid, hc, prev_chunks_next_ptr );
+ /* Free old memory */
+ die_and_free_mem ( tid, hc, prev_chunks_next_ptr );
=20
- /* this has to be after die_and_free_mem, otherwise the
- former succeeds in shorting out the new block, not the
- old, in the case when both are on the same list. */
- add_HG_Chunk ( tid, p_new, new_size );
+ /* this has to be after die_and_free_mem, otherwise the
+ former succeeds in shorting out the new block, not the
+ old, in the case when both are on the same list. */
+ add_HG_Chunk ( tid, p_new, new_size );
+ }
=20
return (void*)p_new;
} =20
Modified: branches/VALGRIND_3_0_BRANCH/massif/ms_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/VALGRIND_3_0_BRANCH/massif/ms_main.c 2005-10-06 09:00:17 UTC=
(rev 4875)
+++ branches/VALGRIND_3_0_BRANCH/massif/ms_main.c 2005-10-06 09:06:59 UTC=
(rev 4876)
@@ -823,24 +823,28 @@
// new size is bigger; make new block, copy shared contents, free=
old
p_new =3D VG_(cli_malloc)(VG_(clo_alignment), new_size);
=20
- for (i =3D 0; i < old_size; i++)
- ((UChar*)p_new)[i] =3D ((UChar*)p_old)[i];
+ if (p_new) {
+ for (i =3D 0; i < old_size; i++)
+ ((UChar*)p_new)[i] =3D ((UChar*)p_old)[i];
=20
- VG_(cli_free)(p_old);
+ VG_(cli_free)(p_old);
+ }
}
- =20
- old_where =3D hc->where;
- new_where =3D get_XCon( tid, /*custom_malloc*/False);
=20
- // Update HP_Chunk
- hc->data =3D (Addr)p_new;
- hc->size =3D new_size;
- hc->where =3D new_where;
+ if (p_new) {
+ old_where =3D hc->where;
+ new_where =3D get_XCon( tid, /*custom_malloc*/False);
=20
- // Update XPt curr_space fields
- if (clo_heap) {
- if (0 !=3D old_size) update_XCon(old_where, -old_size);
- if (0 !=3D new_size) update_XCon(new_where, new_size);
+ // Update HP_Chunk
+ hc->data =3D (Addr)p_new;
+ hc->size =3D new_size;
+ hc->where =3D new_where;
+
+ // Update XPt curr_space fields
+ if (clo_heap) {
+ if (0 !=3D old_size) update_XCon(old_where, -old_size);
+ if (0 !=3D new_size) update_XCon(new_where, new_size);
+ }
}
=20
// If block has moved, have to remove and reinsert in the malloclist
Modified: branches/VALGRIND_3_0_BRANCH/memcheck/mac_malloc_wrappers.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/VALGRIND_3_0_BRANCH/memcheck/mac_malloc_wrappers.c 2005-10-0=
6 09:00:17 UTC (rev 4875)
+++ branches/VALGRIND_3_0_BRANCH/memcheck/mac_malloc_wrappers.c 2005-10-0=
6 09:06:59 UTC (rev 4876)
@@ -421,25 +421,27 @@
/* Get new memory */
p_new =3D (Addr)VG_(cli_malloc)(VG_(clo_alignment), new_size);
=20
- /* First half kept and copied, second half new,=20
- red zones as normal */
- MAC_(ban_mem_heap) ( p_new-MAC_MALLOC_REDZONE_SZB, MAC_MALLOC_REDZ=
ONE_SZB );
- MAC_(copy_mem_heap)( (Addr)p, p_new, mc->size );
- MAC_(new_mem_heap) ( p_new+mc->size, new_size-mc->size, /*inited*/=
False );
- MAC_(ban_mem_heap) ( p_new+new_size, MAC_MALLOC_REDZONE_SZB );
+ if (p_new) {
+ /* First half kept and copied, second half new,=20
+ red zones as normal */
+ MAC_(ban_mem_heap) ( p_new-MAC_MALLOC_REDZONE_SZB, MAC_MALLOC_R=
EDZONE_SZB );
+ MAC_(copy_mem_heap)( (Addr)p, p_new, mc->size );
+ MAC_(new_mem_heap) ( p_new+mc->size, new_size-mc->size, /*inite=
d*/False );
+ MAC_(ban_mem_heap) ( p_new+new_size, MAC_MALLOC_REDZONE_SZB );
=20
- /* Copy from old to new */
- for (i =3D 0; i < mc->size; i++)
- ((UChar*)p_new)[i] =3D ((UChar*)p)[i];
+ /* Copy from old to new */
+ for (i =3D 0; i < mc->size; i++)
+ ((UChar*)p_new)[i] =3D ((UChar*)p)[i];
=20
- /* Free old memory */
- die_and_free_mem ( tid, mc, prev_chunks_next_ptr, MAC_MALLOC_REDZO=
NE_SZB );
+ /* Free old memory */
+ die_and_free_mem ( tid, mc, prev_chunks_next_ptr, MAC_MALLOC_RE=
DZONE_SZB );
=20
- /* this has to be after die_and_free_mem, otherwise the
- former succeeds in shorting out the new block, not the
- old, in the case when both are on the same list. */
- add_MAC_Chunk ( tid, p_new, new_size,=20
- MAC_AllocMalloc, MAC_(malloc_list) );
+ /* this has to be after die_and_free_mem, otherwise the
+ former succeeds in shorting out the new block, not the
+ old, in the case when both are on the same list. */
+ add_MAC_Chunk ( tid, p_new, new_size,=20
+ MAC_AllocMalloc, MAC_(malloc_list) );
+ }
=20
VGP_POPCC(VgpCliMalloc);
return (void*)p_new;
|