|
From: <sv...@va...> - 2011-12-30 03:14:40
|
Author: florian
Date: 2011-12-30 03:09:45 +0000 (Fri, 30 Dec 2011)
New Revision: 12324
Log:
Fix accounting for MC_(realloc). It was inconsistent as compared to
other wrappers in that it took place before the silly-args check.
Testcase and patch by Yann Droneaud (ya...@dr...).
Fixes #281482
Also included is a related fix to MC_(new_block). Incrementing the
alloc counter and updating the allocated memory amount should
occur under the same condition (allocation succeeded).
Added:
trunk/memcheck/tests/accounting.c
trunk/memcheck/tests/accounting.stderr.exp
trunk/memcheck/tests/accounting.vgtest
Modified:
trunk/NEWS
trunk/memcheck/mc_malloc_wrappers.c
trunk/memcheck/tests/Makefile.am
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2011-12-29 08:24:55 UTC (rev 12323)
+++ trunk/NEWS 2011-12-30 03:09:45 UTC (rev 12324)
@@ -30,6 +30,7 @@
286374 Running cachegrind with --branch-sim=yes on 64-bit PowerPC program fails
287858 VG_(strerror): unknown error
289699 vgdb connection in relay mode erroneously closed due to buffer overrun
+281482 valgrind's memcheck incorrect byte allocation count in realloc() for silly argument
Release 3.7.0 (5 November 2011)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Modified: trunk/memcheck/mc_malloc_wrappers.c
===================================================================
--- trunk/memcheck/mc_malloc_wrappers.c 2011-12-29 08:24:55 UTC (rev 12323)
+++ trunk/memcheck/mc_malloc_wrappers.c 2011-12-30 03:09:45 UTC (rev 12324)
@@ -238,8 +238,6 @@
{
ExeContext* ec;
- cmalloc_n_mallocs ++;
-
// Allocate and zero if necessary
if (p) {
tl_assert(MC_AllocCustom == kind);
@@ -258,7 +256,8 @@
}
}
- // Only update this stat if allocation succeeded.
+ // Only update stats if allocation succeeded.
+ cmalloc_n_mallocs ++;
cmalloc_bs_mallocd += (ULong)szB;
ec = VG_(record_ExeContext)(tid, 0/*first_ip_delta*/);
@@ -392,13 +391,13 @@
void* p_new;
SizeT old_szB;
+ if (complain_about_silly_args(new_szB, "realloc"))
+ return NULL;
+
cmalloc_n_frees ++;
cmalloc_n_mallocs ++;
cmalloc_bs_mallocd += (ULong)new_szB;
- if (complain_about_silly_args(new_szB, "realloc"))
- return NULL;
-
/* Remove the old block */
mc = VG_(HT_remove) ( MC_(malloc_list), (UWord)p_old );
if (mc == NULL) {
Modified: trunk/memcheck/tests/Makefile.am
===================================================================
--- trunk/memcheck/tests/Makefile.am 2011-12-29 08:24:55 UTC (rev 12323)
+++ trunk/memcheck/tests/Makefile.am 2011-12-30 03:09:45 UTC (rev 12324)
@@ -47,6 +47,7 @@
noinst_HEADERS = leak.h
EXTRA_DIST = \
+ accounting.stderr.exp accounting.vgtest \
addressable.stderr.exp addressable.stdout.exp addressable.vgtest \
atomic_incs.stderr.exp atomic_incs.vgtest \
atomic_incs.stdout.exp-32bit atomic_incs.stdout.exp-64bit \
@@ -211,6 +212,7 @@
xml1.stderr.exp xml1.stdout.exp xml1.vgtest xml1.stderr.exp-s390x-mvc
check_PROGRAMS = \
+ accounting \
addressable \
atomic_incs \
badaddrvalue badfree badjump badjump2 \
Added: trunk/memcheck/tests/accounting.c
===================================================================
--- trunk/memcheck/tests/accounting.c (rev 0)
+++ trunk/memcheck/tests/accounting.c 2011-12-30 03:09:45 UTC (rev 12324)
@@ -0,0 +1,25 @@
+/*
+ * test case for valgrind realloc() bug
+ */
+
+#include <stdlib.h>
+#include <assert.h>
+
+int
+main(void)
+{
+ void *p;
+ void *r;
+
+ p = malloc(1);
+ assert(p != NULL);
+
+ r = realloc(p, -1);
+ assert(r == NULL);
+
+ free(p);
+
+ return 0;
+}
+
+
Added: trunk/memcheck/tests/accounting.stderr.exp
===================================================================
--- trunk/memcheck/tests/accounting.stderr.exp (rev 0)
+++ trunk/memcheck/tests/accounting.stderr.exp 2011-12-30 03:09:45 UTC (rev 12324)
@@ -0,0 +1,11 @@
+
+Warning: silly arg (-1) to realloc()
+
+HEAP SUMMARY:
+ in use at exit: 0 bytes in 0 blocks
+ total heap usage: 1 allocs, 1 frees, 1 bytes allocated
+
+For a detailed leak analysis, rerun with: --leak-check=full
+
+For counts of detected and suppressed errors, rerun with: -v
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Added: trunk/memcheck/tests/accounting.vgtest
===================================================================
--- trunk/memcheck/tests/accounting.vgtest (rev 0)
+++ trunk/memcheck/tests/accounting.vgtest 2011-12-30 03:09:45 UTC (rev 12324)
@@ -0,0 +1 @@
+prog: accounting
|