other wrappers in that it took place before the silly-args check.
Testcase and patch by Yann Droneaud (yann@droneaud.fr).
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).
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12324
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)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
ExeContext* ec;
- cmalloc_n_mallocs ++;
-
// Allocate and zero if necessary
if (p) {
tl_assert(MC_AllocCustom == kind);
}
}
- // 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*/);
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) {
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 \
xml1.stderr.exp xml1.stdout.exp xml1.vgtest xml1.stderr.exp-s390x-mvc
check_PROGRAMS = \
+ accounting \
addressable \
atomic_incs \
badaddrvalue badfree badjump badjump2 \
--- /dev/null
+/*
+ * 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;
+}
+
+
--- /dev/null
+
+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)
--- /dev/null
+prog: accounting