You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
(122) |
Nov
(152) |
Dec
(69) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(6) |
Feb
(25) |
Mar
(73) |
Apr
(82) |
May
(24) |
Jun
(25) |
Jul
(10) |
Aug
(11) |
Sep
(10) |
Oct
(54) |
Nov
(203) |
Dec
(182) |
| 2004 |
Jan
(307) |
Feb
(305) |
Mar
(430) |
Apr
(312) |
May
(187) |
Jun
(342) |
Jul
(487) |
Aug
(637) |
Sep
(336) |
Oct
(373) |
Nov
(441) |
Dec
(210) |
| 2005 |
Jan
(385) |
Feb
(480) |
Mar
(636) |
Apr
(544) |
May
(679) |
Jun
(625) |
Jul
(810) |
Aug
(838) |
Sep
(634) |
Oct
(521) |
Nov
(965) |
Dec
(543) |
| 2006 |
Jan
(494) |
Feb
(431) |
Mar
(546) |
Apr
(411) |
May
(406) |
Jun
(322) |
Jul
(256) |
Aug
(401) |
Sep
(345) |
Oct
(542) |
Nov
(308) |
Dec
(481) |
| 2007 |
Jan
(427) |
Feb
(326) |
Mar
(367) |
Apr
(255) |
May
(244) |
Jun
(204) |
Jul
(223) |
Aug
(231) |
Sep
(354) |
Oct
(374) |
Nov
(497) |
Dec
(362) |
| 2008 |
Jan
(322) |
Feb
(482) |
Mar
(658) |
Apr
(422) |
May
(476) |
Jun
(396) |
Jul
(455) |
Aug
(267) |
Sep
(280) |
Oct
(253) |
Nov
(232) |
Dec
(304) |
| 2009 |
Jan
(486) |
Feb
(470) |
Mar
(458) |
Apr
(423) |
May
(696) |
Jun
(461) |
Jul
(551) |
Aug
(575) |
Sep
(134) |
Oct
(110) |
Nov
(157) |
Dec
(102) |
| 2010 |
Jan
(226) |
Feb
(86) |
Mar
(147) |
Apr
(117) |
May
(107) |
Jun
(203) |
Jul
(193) |
Aug
(238) |
Sep
(300) |
Oct
(246) |
Nov
(23) |
Dec
(75) |
| 2011 |
Jan
(133) |
Feb
(195) |
Mar
(315) |
Apr
(200) |
May
(267) |
Jun
(293) |
Jul
(353) |
Aug
(237) |
Sep
(278) |
Oct
(611) |
Nov
(274) |
Dec
(260) |
| 2012 |
Jan
(303) |
Feb
(391) |
Mar
(417) |
Apr
(441) |
May
(488) |
Jun
(655) |
Jul
(590) |
Aug
(610) |
Sep
(526) |
Oct
(478) |
Nov
(359) |
Dec
(372) |
| 2013 |
Jan
(467) |
Feb
(226) |
Mar
(391) |
Apr
(281) |
May
(299) |
Jun
(252) |
Jul
(311) |
Aug
(352) |
Sep
(481) |
Oct
(571) |
Nov
(222) |
Dec
(231) |
| 2014 |
Jan
(185) |
Feb
(329) |
Mar
(245) |
Apr
(238) |
May
(281) |
Jun
(399) |
Jul
(382) |
Aug
(500) |
Sep
(579) |
Oct
(435) |
Nov
(487) |
Dec
(256) |
| 2015 |
Jan
(338) |
Feb
(357) |
Mar
(330) |
Apr
(294) |
May
(191) |
Jun
(108) |
Jul
(142) |
Aug
(261) |
Sep
(190) |
Oct
(54) |
Nov
(83) |
Dec
(22) |
| 2016 |
Jan
(49) |
Feb
(89) |
Mar
(33) |
Apr
(50) |
May
(27) |
Jun
(34) |
Jul
(53) |
Aug
(53) |
Sep
(98) |
Oct
(206) |
Nov
(93) |
Dec
(53) |
| 2017 |
Jan
(65) |
Feb
(82) |
Mar
(102) |
Apr
(86) |
May
(187) |
Jun
(67) |
Jul
(23) |
Aug
(93) |
Sep
(65) |
Oct
(45) |
Nov
(35) |
Dec
(17) |
| 2018 |
Jan
(26) |
Feb
(35) |
Mar
(38) |
Apr
(32) |
May
(8) |
Jun
(43) |
Jul
(27) |
Aug
(30) |
Sep
(43) |
Oct
(42) |
Nov
(38) |
Dec
(67) |
| 2019 |
Jan
(32) |
Feb
(37) |
Mar
(53) |
Apr
(64) |
May
(49) |
Jun
(18) |
Jul
(14) |
Aug
(53) |
Sep
(25) |
Oct
(30) |
Nov
(49) |
Dec
(31) |
| 2020 |
Jan
(87) |
Feb
(45) |
Mar
(37) |
Apr
(51) |
May
(99) |
Jun
(36) |
Jul
(11) |
Aug
(14) |
Sep
(20) |
Oct
(24) |
Nov
(40) |
Dec
(23) |
| 2021 |
Jan
(14) |
Feb
(53) |
Mar
(85) |
Apr
(15) |
May
(19) |
Jun
(3) |
Jul
(14) |
Aug
(1) |
Sep
(57) |
Oct
(73) |
Nov
(56) |
Dec
(22) |
| 2022 |
Jan
(3) |
Feb
(22) |
Mar
(6) |
Apr
(55) |
May
(46) |
Jun
(39) |
Jul
(15) |
Aug
(9) |
Sep
(11) |
Oct
(34) |
Nov
(20) |
Dec
(36) |
| 2023 |
Jan
(79) |
Feb
(41) |
Mar
(99) |
Apr
(169) |
May
(48) |
Jun
(16) |
Jul
(16) |
Aug
(57) |
Sep
(19) |
Oct
|
Nov
|
Dec
|
|
From: Paul F. <pa...@so...> - 2023-03-21 21:11:59
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=394fa9223aff48b6b344f0d55f8bc409a5425486 commit 394fa9223aff48b6b344f0d55f8bc409a5425486 Author: Paul Floyd <pj...@wa...> Date: Tue Mar 21 22:11:11 2023 +0100 Solaris: fix build, another aligned alloc typo Diff: --- coregrind/m_replacemalloc/vg_replace_malloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index d3f33e66cf..db2fc5f309 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -1617,7 +1617,7 @@ extern int *___errno (void) __attribute__((weak)); #endif #if defined(VGO_solaris) -#define VG_MEMALIGD_ALIGN_FACTOR_FOUR 1 +#define VG_MEMALIGN_ALIGN_FACTOR_FOUR 1 #else #define VG_MEMALIGN_ALIGN_FACTOR_FOUR 0 #endif |
|
From: Paul F. <pa...@so...> - 2023-03-17 18:49:15
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=022a9caf40ceb32b8dfe258a8f2777f6299457d3 commit 022a9caf40ceb32b8dfe258a8f2777f6299457d3 Author: Paul Floyd <pj...@wa...> Date: Fri Mar 17 19:48:08 2023 +0100 Bug 467482 - Build failure on aarch64 Alpine Patch submitted by fan...@gm... Diff: --- NEWS | 9 ++++++--- coregrind/m_replacemalloc/vg_replace_malloc.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index cd20f7773a..8ede199d67 100644 --- a/NEWS +++ b/NEWS @@ -10,9 +10,6 @@ AMD64/macOS 10.13 and nanoMIPS/Linux. * ==================== CORE CHANGES =================== -* Make the address space limit on FreeBSD amd64 128Gbytes - (the same as Linux and Solaris, it was 32Gbytes) - * When GDB is used to debug a program running under valgrind using the valgrind gdbserver, GDB will automatically load some python code provided in valgrind defining GDB front end commands @@ -56,6 +53,11 @@ AMD64/macOS 10.13 and nanoMIPS/Linux. option to change the behaviour of Valgrind: --realloc-zero-bytes-frees=yes|no [yes on Linux glibc, no otherwise] +* ================== PLATFORM CHANGES ================= + +* Make the address space limit on FreeBSD amd64 128Gbytes + (the same as Linux and Solaris, it was 32Gbytes) + * ==================== TOOL CHANGES =================== * Memcheck: @@ -125,6 +127,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 464969 D language demangling 465435 m_libcfile.c:66 (vgPlain_safe_fd): Assertion 'newfd >= VG_(fd_hard_limit)' failed. 466104 aligned_alloc problems, part 1 +467482 Build failure on aarch64 Alpine n-i-bz FreeBSD rfork syscall fail with EINVAL or ENOSYS rather than VG_(unimplemented) To see details of a given bug, visit diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index c46e719c94..d3f33e66cf 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -1607,7 +1607,7 @@ extern int *___errno (void) __attribute__((weak)); #if defined(VGO_freebsd) #define VG_MEMALIGN_MAKE_SIZE_MULTIPLE_ALIGN 1 #else -#define VG_MEMALIG_MAKE_SIZE_MULTIPLE_ALIGN 0 +#define VG_MEMALIGN_MAKE_SIZE_MULTIPLE_ALIGN 0 #endif #if defined(VGO_solaris) |
|
From: Nicholas N. <n.n...@gm...> - 2023-03-17 05:24:31
|
I have finished the rewrite. I am happy with the new code, it is much better than the old code. You can see it at https://bugs.kde.org/show_bug.cgi?id=467472. I plan to merge it by the end of next week, and I am happy to hear any suggestions. I also have some good news about the `cg_annotate.in`/`cg_annotate` split. I learned that you can generate the latter from the former very quickly with `config.status cachegrind/cg_annotate.in`. Also, this can be done automatically from some make targets. So I ended up creating a new make target `make ann` that can be run within the `cachegrind` directory. It runs the various Python formatters, type-checkers, and linters I am using on `cg_annotate.in` and then generates `cg_annotate`. It's a one-step "build" command that runs quickly, which is great. Nick On Wed, 15 Mar 2023 at 06:15, Nicholas Nethercote <n.n...@gm...> wrote: > On Sun, 12 Mar 2023 at 23:01, Paul Floyd <pj...@wa...> wrote: > >> >> The only think I can think of to get the version is to use something like >> >> pkg-config --modversion valgrind >> > > Thanks for the suggestion. Unfortunately this could cause misleading > results. E.g. if I have Valgrind installed on my system but I also have a > development version, when I run the development version of `cg_annotate > --version` it will claim to be the installed version. I think the `@VERSION@` > junk is unavoidable. > > Nick > |
|
From: Nicholas N. <n.n...@gm...> - 2023-03-14 19:16:17
|
On Sun, 12 Mar 2023 at 23:01, Paul Floyd <pj...@wa...> wrote: > > The only think I can think of to get the version is to use something like > > pkg-config --modversion valgrind > Thanks for the suggestion. Unfortunately this could cause misleading results. E.g. if I have Valgrind installed on my system but I also have a development version, when I run the development version of `cg_annotate --version` it will claim to be the installed version. I think the `@VERSION@` junk is unavoidable. Nick |
|
From: Paul F. <pj...@wa...> - 2023-03-12 15:56:06
|
Hi
I'm starting to look at adding alignment checks for the various aligned
allocators in memcheck.
That will give us errors like ASAN:
==89579==ERROR: AddressSanitizer: invalid alignment requested in
posix_memalign: -1, alignment must be a power of two and a multiple of
sizeof(void*) == 8 (thread T0)
#0 0x28e487 in posix_memalign
/usr/src/contrib/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:210:3
#1 0x2b7c00 in main
/usr/home/paulf/scratch/valgrind/memcheck/tests/posix_memalign.c:39:10
#2 0x23542f in _start /usr/src/lib/csu/amd64/crt1_c.c:75:7
#3 0x8002dd007 (<unknown module>)
There are two problems. Firstly we map 4 C aligned allocation functions
(memalign, posix_memalign, aligned_alloc and valloc) to our one wrapper
interface, tl_memalign. So we don't know which function to check for.
Secondly we do argument checking / fixup in vg_replace_malloc. That
means that at the moment invalid args often cause a fail before getting
to memcheck.
To discriminate between the functions, the easiest thing will probably
be to add an enum tag (splitting tl_memalign into 3 will be a lot of
effort).
I see two possible solutions for the checks.
1/ move all the checking later so that memcheck can see the arguments.
2/ use a client req before all of the argument twiddling
I'm leaning more to using a client req as it has less impact on the
existing flow.
Any thoughts?
A+
Paul
|
|
From: Paul F. <pj...@wa...> - 2023-03-12 12:01:02
|
On 06-03-23 12:03, Nicholas Nethercote wrote: > Hi, > > Perl was a reasonable choice for `cg_annotate` when I first wrote it 20+ > years ago. But it's unfortunate now, with Perl being (a) a pretty weird > and horrible language, and (b) moribund. > > I'd like to rewrite it (and `cg_diff`) in Python, which will make > maintenance easier. I see that we already have some Python in Valgrind: > `coregrind/m_gdbserver/valgrind-monitor.py` and > `coregrind/m_gdbserver/valgrind-monitor-def.py`. Therefore I don't think > this should be controversial. > > But I might as well ask, just in case: any objections or advice? Because > these are single file scripts, we avoid all the usual problems of Python > packaging, and just use `cp` as the package manager :) > > On a related note, the `cg_annotate.in > <http://cg_annotate.in>`/`cg_annotate` split is annoying. The only > reason for it now is to auto-embed the version number into the script, > via the configure `@VERSION@` variable, for `cg_annotate --version` > output. Does anyone know of a way to achieve that without requiring > configure? Hi Nick Scripting languages aren't my strong point, but I'd say for me Python is the least worst choice. The only think I can think of to get the version is to use something like pkg-config --modversion valgrind Cheers Paul |
|
From: Paul F. <pa...@so...> - 2023-03-12 10:13:08
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=50f65336127b5f63c8af55544ce3e6a9bc834355 commit 50f65336127b5f63c8af55544ce3e6a9bc834355 Author: Paul Floyd <pj...@wa...> Date: Sun Mar 12 11:12:29 2023 +0100 coverity: a couple of potential buffer overruns Diff: --- coregrind/launcher-freebsd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/coregrind/launcher-freebsd.c b/coregrind/launcher-freebsd.c index 792a4bd239..030b183b57 100644 --- a/coregrind/launcher-freebsd.c +++ b/coregrind/launcher-freebsd.c @@ -83,7 +83,7 @@ static const char *find_client(const char *clientname) while (path) { if ((colon = strchr(path, ':')) == NULL) { - strcpy(fullname, path); + strlcpy(fullname, path, PATH_MAX); path = NULL; } else { memcpy(fullname, path, colon - path); @@ -91,8 +91,8 @@ static const char *find_client(const char *clientname) path = colon + 1; } - strcat(fullname, "/"); - strcat(fullname, clientname); + strlcat(fullname, "/", PATH_MAX); + strlcat(fullname, clientname, PATH_MAX); if (access(fullname, R_OK|X_OK) == 0) { return fullname; |
|
From: Paul F. <pa...@so...> - 2023-03-12 08:40:29
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=d3a49926ad4c35e7d72bd435cf111d4cf507be54 commit d3a49926ad4c35e7d72bd435cf111d4cf507be54 Author: Paul Floyd <pj...@wa...> Date: Sun Mar 12 09:39:35 2023 +0100 coverity: printf args format mismatch Diff: --- coregrind/vgdb-invoker-freebsd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coregrind/vgdb-invoker-freebsd.c b/coregrind/vgdb-invoker-freebsd.c index 4a8a97cb7c..27e1943685 100644 --- a/coregrind/vgdb-invoker-freebsd.c +++ b/coregrind/vgdb-invoker-freebsd.c @@ -315,7 +315,7 @@ Bool attach (pid_t pid, const char *msg) res = ptrace (PT_ATTACH, pid, 0, 0); if (res != 0) { if (output_error || debuglevel > 0) { - ERROR(errno, "%s PT_ATTACH pid %d %ld\n", msg, pid, res); + ERROR(errno, "%s PT_ATTACH pid %d %d\n", msg, pid, res); if (initial_attach) { output_error = False; } |
|
From: Paul F. <pa...@so...> - 2023-03-12 08:22:41
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=18c278f386ba0e028800faa9eac658dfe6e727b1 commit 18c278f386ba0e028800faa9eac658dfe6e727b1 Author: Paul Floyd <pj...@wa...> Date: Sun Mar 12 09:22:10 2023 +0100 coverity: copy paste error Diff: --- coregrind/m_syswrap/syswrap-amd64-freebsd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coregrind/m_syswrap/syswrap-amd64-freebsd.c b/coregrind/m_syswrap/syswrap-amd64-freebsd.c index e54b157dd7..00c353ae41 100644 --- a/coregrind/m_syswrap/syswrap-amd64-freebsd.c +++ b/coregrind/m_syswrap/syswrap-amd64-freebsd.c @@ -962,7 +962,7 @@ POST(sys_wait6) } if (ARG6) { - POST_MEM_WRITE(ARG5, sizeof(vki_siginfo_t)); + POST_MEM_WRITE(ARG6, sizeof(vki_siginfo_t)); } } |
|
From: Paul F. <pa...@so...> - 2023-03-12 07:22:33
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=a1bb70bbf1f627461c30c626cbb853fce9411926 commit a1bb70bbf1f627461c30c626cbb853fce9411926 Author: Paul Floyd <pj...@wa...> Date: Sun Mar 12 08:21:55 2023 +0100 FreeBSD: fix a syswrap compiler warning Diff: --- coregrind/m_syswrap/syswrap-freebsd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index 0d64d57605..fd4dff4da4 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -4898,7 +4898,7 @@ POST(sys_rtprio_thread) PRE(sys_sctp_generic_sendmsg) { *flags |= SfMayBlock; - PRINT("sys_sctp_generic_sendmsg ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )",SARG1,ARG2,ARG3,ARG4,SARG5,ARG6,SARG7); + PRINT("sys_sctp_generic_sendmsg ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )",SARG1,ARG2,SARG3,ARG4,SARG5,ARG6,SARG7); PRE_REG_READ7(ssize_t, "sctp_generic_sendmsg", int, s, void *, msg, int, msglen, struct sockaddr *, to, socklen_t, len, |
|
From: Paul F. <pa...@so...> - 2023-03-12 07:21:47
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=8532c8b5e43ba4453ebfbe3169e4e9fc973fef3b commit 8532c8b5e43ba4453ebfbe3169e4e9fc973fef3b Author: Paul Floyd <pj...@wa...> Date: Sun Mar 12 08:20:57 2023 +0100 regtest: add an s390 expected for sized_aligned_new_delete_args Diff: --- memcheck/tests/Makefile.am | 1 + .../sized_aligned_new_delete_args.stderr.exp-s390 | 96 ++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index 7600981687..0509d45869 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -143,6 +143,7 @@ EXTRA_DIST = \ sized_aligned_new_delete_args.vgtest \ sized_aligned_new_delete_args.stderr.exp_32 \ sized_aligned_new_delete_args.stderr.exp-gcc \ + sized_aligned_new_delete_args.stderr.exp-s390 \ sized_aligned_new_delete_misaligned.stderr.exp \ sized_aligned_new_delete_misaligned.vgtest \ deep-backtrace.vgtest deep-backtrace.stderr.exp \ diff --git a/memcheck/tests/sized_aligned_new_delete_args.stderr.exp-s390 b/memcheck/tests/sized_aligned_new_delete_args.stderr.exp-s390 new file mode 100644 index 0000000000..ea74f0f3d7 --- /dev/null +++ b/memcheck/tests/sized_aligned_new_delete_args.stderr.exp-s390 @@ -0,0 +1,96 @@ +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:16) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:16) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:16) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:17) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:19) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:19) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:19) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:20) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:24) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:24) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:24) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:24) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:25) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:27) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:27) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:27) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:27) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:28) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: ...operator delete... (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:31) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, unsigned long) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:34) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:37) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:37) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:40) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:40) + |
|
From: Paul F. <pa...@so...> - 2023-03-11 15:49:13
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=96a66dfda6e0f4c43e633aa4bd2a60389073a41c commit 96a66dfda6e0f4c43e633aa4bd2a60389073a41c Author: Paul Floyd <pj...@wa...> Date: Sat Mar 11 16:47:56 2023 +0100 doc: Add asan equivalent to --realloc-zero-bytes-frees to manual-core Diff: --- docs/xml/manual-core.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/xml/manual-core.xml b/docs/xml/manual-core.xml index 20886fe49e..296fc1c2a9 100644 --- a/docs/xml/manual-core.xml +++ b/docs/xml/manual-core.xml @@ -1802,6 +1802,9 @@ that can report errors, e.g. Memcheck, but not Cachegrind.</para> consider using <computeroutput>--realloc-zero-bytes-frees=no</computeroutput>. </para> + <para>Address Sanitizer has a similar and even wordier option + <computeroutput>allocator_frees_and_returns_null_on_realloc_zero</computeroutput>. + </para> </listitem> </varlistentry> |
|
From: Paul F. <pa...@so...> - 2023-03-11 15:33:16
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=036bf06734321b352e1069b561a4730e5daff52f commit 036bf06734321b352e1069b561a4730e5daff52f Author: Paul Floyd <pj...@wa...> Date: Sat Mar 11 16:31:43 2023 +0100 Refactor: reorder a few structs to make them more compact Used pahole to find candidates. Don't have any performance measurements, but it won't do any harm. Diff: --- coregrind/m_errormgr.c | 4 ++-- coregrind/m_hashtable.c | 2 +- memcheck/mc_include.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c index 52505ba5b2..6be637190a 100644 --- a/coregrind/m_errormgr.c +++ b/coregrind/m_errormgr.c @@ -130,9 +130,9 @@ struct _Error { // which it can be referred to afterwords. Currently only used for // XML printing. UInt unique; + Int count; // NULL if unsuppressed; or ptr to suppression record. Supp* supp; - Int count; // The tool-specific part ThreadId tid; // Initialised by core @@ -225,8 +225,8 @@ typedef (0..)) for 'skind'. */ struct _Supp { struct _Supp* next; - Int count; // The number of times this error has been suppressed. HChar* sname; // The name by which the suppression is referred to. + Int count; // The number of times this error has been suppressed. // Index in VG_(clo_suppressions) giving filename from which suppression // was read, and the lineno in this file where sname was read. diff --git a/coregrind/m_hashtable.c b/coregrind/m_hashtable.c index 19c604d3a6..586cfcc4f3 100644 --- a/coregrind/m_hashtable.c +++ b/coregrind/m_hashtable.c @@ -45,8 +45,8 @@ struct _VgHashTable { UInt n_elements; VgHashNode* iterNode; // current iterator node UInt iterChain; // next chain to be traversed by the iterator - VgHashNode** chains; // expanding array of hash chains Bool iterOK; // table safe to iterate over? + VgHashNode** chains; // expanding array of hash chains const HChar* name; // name of table (for debugging only) }; diff --git a/memcheck/mc_include.h b/memcheck/mc_include.h index 3c1b1a7cd4..c30ec48efb 100644 --- a/memcheck/mc_include.h +++ b/memcheck/mc_include.h @@ -455,9 +455,9 @@ typedef SizeT szB; // Sum of all MC_Chunk.szB values. SizeT indirect_szB; // Sum of all LC_Extra.indirect_szB values. UInt num_blocks; // Number of blocks represented by the record. + UInt old_num_blocks; // output only the changed/new loss records SizeT old_szB; // old_* values are the values found during the SizeT old_indirect_szB; // previous leak search. old_* values are used to - UInt old_num_blocks; // output only the changed/new loss records } LossRecord; |
|
From: Paul F. <pa...@so...> - 2023-03-11 07:08:07
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=678b685c7b0d982a5a1142ff598ab0f2eab8e794 commit 678b685c7b0d982a5a1142ff598ab0f2eab8e794 Author: Paul Floyd <pj...@wa...> Date: Sat Mar 11 08:07:06 2023 +0100 regtest: update one expected after fixing realloc_size_zero_mismatch.cpp Diff: --- memcheck/tests/realloc_size_zero_mismatch.stderr.exp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/memcheck/tests/realloc_size_zero_mismatch.stderr.exp b/memcheck/tests/realloc_size_zero_mismatch.stderr.exp index f7c535574b..141ab8b7ad 100644 --- a/memcheck/tests/realloc_size_zero_mismatch.stderr.exp +++ b/memcheck/tests/realloc_size_zero_mismatch.stderr.exp @@ -1,28 +1,28 @@ realloc() with size 0 at 0x........: realloc (vg_replace_malloc.c:...) - by 0x........: main (realloc_size_zero_mismatch.cpp:15) + by 0x........: main (realloc_size_zero_mismatch.cpp:16) Address 0x........ is 0 bytes inside a block of size 1,024 alloc'd at 0x........: ...operator new[]... (vg_replace_malloc.c:...) - by 0x........: main (realloc_size_zero_mismatch.cpp:11) + by 0x........: main (realloc_size_zero_mismatch.cpp:12) Mismatched free() / delete / delete [] at 0x........: realloc (vg_replace_malloc.c:...) - by 0x........: main (realloc_size_zero_mismatch.cpp:15) + by 0x........: main (realloc_size_zero_mismatch.cpp:16) Address 0x........ is 0 bytes inside a block of size 1,024 alloc'd at 0x........: ...operator new[]... (vg_replace_malloc.c:...) - by 0x........: main (realloc_size_zero_mismatch.cpp:11) + by 0x........: main (realloc_size_zero_mismatch.cpp:12) Mismatched free() / delete / delete [] at 0x........: ...operator delete[]... (vg_replace_malloc.c:...) - by 0x........: main (realloc_size_zero_mismatch.cpp:25) + by 0x........: main (realloc_size_zero_mismatch.cpp:26) Address 0x........ is 0 bytes inside a block of size 1 alloc'd at 0x........: realloc (vg_replace_malloc.c:...) - by 0x........: main (realloc_size_zero_mismatch.cpp:15) + by 0x........: main (realloc_size_zero_mismatch.cpp:16) Mismatched free() / delete / delete [] at 0x........: ...operator delete[]... (vg_replace_malloc.c:...) - by 0x........: main (realloc_size_zero_mismatch.cpp:40) + by 0x........: main (realloc_size_zero_mismatch.cpp:41) Address 0x........ is 0 bytes after a block of size 0 alloc'd at 0x........: realloc (vg_replace_malloc.c:...) - by 0x........: main (realloc_size_zero_mismatch.cpp:30) + by 0x........: main (realloc_size_zero_mismatch.cpp:31) |
|
From: Paul F. <pa...@so...> - 2023-03-11 05:50:13
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=d9a8c601af8182f5b0b11da6a6e0f657fa087405 commit d9a8c601af8182f5b0b11da6a6e0f657fa087405 Author: Paul Floyd <pj...@wa...> Date: Sat Mar 11 06:49:13 2023 +0100 regtest: build failure on Linux ppc64le, missing header Diff: --- memcheck/tests/realloc_size_zero_mismatch.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/memcheck/tests/realloc_size_zero_mismatch.cpp b/memcheck/tests/realloc_size_zero_mismatch.cpp index 13d1e58832..ba809ee17b 100644 --- a/memcheck/tests/realloc_size_zero_mismatch.cpp +++ b/memcheck/tests/realloc_size_zero_mismatch.cpp @@ -1,5 +1,6 @@ #include <iostream> #include <cstdlib> +#include <cstdio> #include <cerrno> using std::realloc; |
|
From: Paul F. <pa...@so...> - 2023-03-10 21:00:41
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=50bded71b23cb11a8b6c1b6eaf6e3abcc05a06c2 commit 50bded71b23cb11a8b6c1b6eaf6e3abcc05a06c2 Author: Paul Floyd <pj...@wa...> Date: Fri Mar 10 21:55:14 2023 +0100 Bug 436413 - Warn about realloc of size zero Adds a new warning to memcheck when realloc is used with a size of 0. For a long time this has been "implementation defined" and so non-portable. With C23 it will become UB. Also adds a switch to turn off the error generation and a second switch to select between the most common "implementation" behaviours. The defaults for this second switch are baked in at build time. Diff: --- .gitignore | 2 + NEWS | 26 +++++++++ coregrind/m_main.c | 4 ++ coregrind/m_replacemalloc/replacemalloc_core.c | 6 ++ coregrind/m_replacemalloc/vg_replace_malloc.c | 60 ++++++++------------ coregrind/m_scheduler/scheduler.c | 1 + coregrind/pub_core_replacemalloc.h | 1 + dhat/dh_main.c | 7 ++- docs/xml/manual-core.xml | 18 ++++++ drd/drd_malloc_wrappers.c | 8 ++- drd/tests/memory_allocation.c | 7 +-- helgrind/hg_main.c | 19 +++++++ include/pub_tool_replacemalloc.h | 2 + massif/ms_main.c | 14 +++++ massif/tests/realloc.post.exp | 2 +- massif/tests/realloc.vgtest | 3 +- memcheck/docs/mc-manual.xml | 27 +++++++++ memcheck/mc_errors.c | 65 ++++++++++++++++++---- memcheck/mc_include.h | 4 ++ memcheck/mc_main.c | 4 ++ memcheck/mc_malloc_wrappers.c | 19 +++++++ memcheck/tests/Makefile.am | 18 ++++++ memcheck/tests/amd64-freebsd/reallocf.c | 1 + memcheck/tests/amd64-freebsd/reallocf.stderr.exp | 11 +++- memcheck/tests/freebsd/static_allocs.stderr.exp | 14 ++++- memcheck/tests/realloc_size_zero.c | 39 +++++++++++++ memcheck/tests/realloc_size_zero.stderr.exp | 7 +++ memcheck/tests/realloc_size_zero.stdout.exp-glibc | 2 + memcheck/tests/realloc_size_zero.stdout.exp-other | 2 + memcheck/tests/realloc_size_zero.supp | 7 +++ memcheck/tests/realloc_size_zero.vgtest | 2 + memcheck/tests/realloc_size_zero_mismatch.cpp | 41 ++++++++++++++ .../tests/realloc_size_zero_mismatch.stderr.exp | 28 ++++++++++ .../tests/realloc_size_zero_mismatch.stdout.exp | 2 + memcheck/tests/realloc_size_zero_mismatch.vgtest | 2 + memcheck/tests/realloc_size_zero_no.stderr.exp | 7 +++ memcheck/tests/realloc_size_zero_no.stdout.exp | 2 + memcheck/tests/realloc_size_zero_no.vgtest | 2 + memcheck/tests/realloc_size_zero_off.stderr.exp | 0 memcheck/tests/realloc_size_zero_off.stdout.exp | 2 + memcheck/tests/realloc_size_zero_off.vgtest | 2 + memcheck/tests/realloc_size_zero_supp.stderr.exp | 0 memcheck/tests/realloc_size_zero_supp.stdout.exp | 2 + memcheck/tests/realloc_size_zero_supp.vgtest | 2 + memcheck/tests/realloc_size_zero_yes.stderr.exp | 7 +++ memcheck/tests/realloc_size_zero_yes.stdout.exp | 2 + memcheck/tests/realloc_size_zero_yes.vgtest | 2 + none/tests/cmdline1.stdout.exp | 4 ++ none/tests/cmdline1.stdout.exp-non-linux | 4 ++ none/tests/cmdline2.stdout.exp | 4 ++ none/tests/cmdline2.stdout.exp-non-linux | 4 ++ 51 files changed, 457 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index d5e341063e..a88ab4dd43 100644 --- a/.gitignore +++ b/.gitignore @@ -947,6 +947,8 @@ /memcheck/tests/posix_memalign /memcheck/tests/post-syscall /memcheck/tests/reach_thread_register +/memcheck/tests/realloc_size_zero +/memcheck/tests/realloc_size_zero_mismatch /memcheck/tests/realloc1 /memcheck/tests/realloc2 /memcheck/tests/realloc3 diff --git a/NEWS b/NEWS index bc3f4a363b..cd20f7773a 100644 --- a/NEWS +++ b/NEWS @@ -37,6 +37,25 @@ AMD64/macOS 10.13 and nanoMIPS/Linux. $3 = 40 (gdb) monitor who_point_at 0x1130a0 40 +* The behaviour of realloc with a size of zero can now + be changed for tools that intercept malloc. Those + tools are memcheck, helgrind, drd, massif and dhat. + Realloc implementations generally do one of two things + - free the memory like free() and return NULL + (GNU libc and ptmalloc). + - either free the memory and then allocate a + minumum siized block or just return the + original pointer. Return NULL if the + allocation of the minimum sized block fails + (jemalloc, musl, snmalloc, Solaris, macOS). + When Valgrind is configured and built it will + try to match the OS and libc behaviour. However + if you are using a non-default library to replace + malloc and family (e.g., musl on a glibc Linux or + tcmalloc on FreeBSD) then you can use a command line + option to change the behaviour of Valgrind: + --realloc-zero-bytes-frees=yes|no [yes on Linux glibc, no otherwise] + * ==================== TOOL CHANGES =================== * Memcheck: @@ -50,6 +69,13 @@ AMD64/macOS 10.13 and nanoMIPS/Linux. the new loss records have a "new" marker. - Valgrind now contains python code that defines GDB memcheck front end monitor commands. See CORE CHANGES. + - Performs checks for the use of realloc with a size of zero. + This is non-portable and a source of errors. If memcheck + detects such a usage it will generate an error + realloc() with size 0 + followed by the usual callstacks. + A switch has been added to allow this to be turned off: + --show-realloc-size-zero=yes|no [yes] * Helgrind: - The option ---history-backtrace-size=<number> allows to configure diff --git a/coregrind/m_main.c b/coregrind/m_main.c index b5501b5f31..0a7d81389e 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -243,6 +243,10 @@ static void usage_NORETURN ( int need_help ) " attempt to avoid expensive address-space-resync operations\n" " --max-threads=<number> maximum number of threads that valgrind can\n" " handle [%d]\n" +" --realloc-zero-bytes-frees=yes|no [yes on Linux glibc, no otherwise]\n" +" should calls to realloc with a size of 0\n" +" free memory and return NULL or\n" +" allocate/resize and return non-NULL\n" "\n"; const HChar usage2[] = diff --git a/coregrind/m_replacemalloc/replacemalloc_core.c b/coregrind/m_replacemalloc/replacemalloc_core.c index 4b7d8ae609..6c86a8ce17 100644 --- a/coregrind/m_replacemalloc/replacemalloc_core.c +++ b/coregrind/m_replacemalloc/replacemalloc_core.c @@ -45,6 +45,11 @@ /* DEBUG: print malloc details? default: NO */ Bool VG_(clo_trace_malloc) = False; +#if defined(VGO_linux) && !defined(MUSL_LIBC) +Bool VG_(clo_realloc_zero_bytes_frees) = True; +#else +Bool VG_(clo_realloc_zero_bytes_frees) = False; +#endif /* Minimum alignment in functions that don't specify alignment explicitly. default: 0, i.e. use VG_MIN_MALLOC_SZB. */ @@ -75,6 +80,7 @@ Bool VG_(replacement_malloc_process_cmd_line_option)(const HChar* arg) VG_(clo_xtree_compress_strings)) {} else if VG_BOOL_CLO(arg, "--trace-malloc", VG_(clo_trace_malloc)) {} + else if VG_BOOL_CLO(arg, "--realloc-zero-bytes-frees", VG_(clo_realloc_zero_bytes_frees)) {} else return False; diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 3379aa96f7..c46e719c94 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -1460,20 +1460,16 @@ extern int *___errno (void) __attribute__((weak)); void* v; \ \ DO_INIT; \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(ptrV); \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(new_size); \ MALLOC_TRACE("zone_realloc(%p,%p,%llu)", zone, ptrV, (ULong)new_size ); \ - \ - if (ptrV == NULL) \ - /* We need to call a malloc-like function; so let's use \ - one which we know exists. GrP fixme use zonemalloc instead? */ \ - return VG_REPLACE_FUNCTION_EZU(10010,VG_Z_LIBC_SONAME,malloc) \ - (new_size); \ - if (new_size <= 0) { \ - VG_REPLACE_FUNCTION_EZU(10050,VG_Z_LIBC_SONAME,free)(ptrV); \ - MALLOC_TRACE(" = 0\n"); \ - return NULL; \ - } \ v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \ MALLOC_TRACE(" = %p\n", v ); \ + if (v == NULL) { \ + if (!(new_size == 0U && info.clo_realloc_zero_bytes_frees == True)) {\ + SET_ERRNO_ENOMEM; \ + } \ + } \ return v; \ } @@ -1487,21 +1483,16 @@ extern int *___errno (void) __attribute__((weak)); void* v; \ \ DO_INIT; \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(ptrV); \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(new_size); \ MALLOC_TRACE("realloc(%p,%llu)", ptrV, (ULong)new_size ); \ - \ - if (ptrV == NULL) \ - /* We need to call a malloc-like function; so let's use \ - one which we know exists. */ \ - return VG_REPLACE_FUNCTION_EZU(10010,VG_Z_LIBC_SONAME,malloc) \ - (new_size); \ - if (new_size <= 0) { \ - VG_REPLACE_FUNCTION_EZU(10050,VG_Z_LIBC_SONAME,free)(ptrV); \ - MALLOC_TRACE(" = 0\n"); \ - return NULL; \ - } \ v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \ MALLOC_TRACE(" = %p\n", v ); \ - if (!v) SET_ERRNO_ENOMEM; \ + if (v == NULL) { \ + if (!(new_size == 0U && info.clo_realloc_zero_bytes_frees == True)) {\ + SET_ERRNO_ENOMEM; \ + } \ + } \ return v; \ } @@ -1514,24 +1505,17 @@ extern int *___errno (void) __attribute__((weak)); { \ void* v; \ \ - if (!init_done) init(); \ + DO_INIT; \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(ptrV); \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(new_size); \ MALLOC_TRACE("reallocf(%p,%llu)", ptrV, (ULong)new_size ); \ - \ - if (ptrV == NULL) \ - /* We need to call a malloc-like function; so let's use \ - one which we know exists. */ \ - return VG_REPLACE_FUNCTION_EZU(10010,VG_Z_LIBC_SONAME,malloc) \ - (new_size); \ - if (new_size == 0) { \ - VG_REPLACE_FUNCTION_EZU(10050,VG_Z_LIBC_SONAME,free)(ptrV); \ - MALLOC_TRACE(" = 0\n"); \ - return ptrV; \ - } \ v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \ MALLOC_TRACE(" = %p\n", v ); \ - if (v == NULL) {\ - VG_REPLACE_FUNCTION_EZU(10050,VG_Z_LIBC_SONAME,free)(ptrV); \ - SET_ERRNO_ENOMEM; \ + if (v == NULL) { \ + if (!(new_size == 0U && info.clo_realloc_zero_bytes_frees == True)) {\ + VG_REPLACE_FUNCTION_EZU(10050,VG_Z_LIBC_SONAME,free)(ptrV); \ + SET_ERRNO_ENOMEM; \ + } \ } \ MALLOC_TRACE(" = %p\n", v ); \ return v; \ diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c index 788018c3e9..3062c1afc3 100644 --- a/coregrind/m_scheduler/scheduler.c +++ b/coregrind/m_scheduler/scheduler.c @@ -2109,6 +2109,7 @@ void do_client_request ( ThreadId tid ) info->mallinfo = VG_(mallinfo); info->clo_trace_malloc = VG_(clo_trace_malloc); + info->clo_realloc_zero_bytes_frees = VG_(clo_realloc_zero_bytes_frees); SET_CLREQ_RETVAL( tid, 0 ); /* return value is meaningless */ diff --git a/coregrind/pub_core_replacemalloc.h b/coregrind/pub_core_replacemalloc.h index cbf7f8ecdd..bfd137a8b2 100644 --- a/coregrind/pub_core_replacemalloc.h +++ b/coregrind/pub_core_replacemalloc.h @@ -55,6 +55,7 @@ struct vg_mallocfunc_info { SizeT (*tl_malloc_usable_size) (ThreadId tid, void* payload); void (*mallinfo) (ThreadId tid, struct vg_mallinfo* mi); Bool clo_trace_malloc; + Bool clo_realloc_zero_bytes_frees; }; #endif // __PUB_CORE_REPLACEMALLOC_H diff --git a/dhat/dh_main.c b/dhat/dh_main.c index 6f15ae82e3..57d94237c5 100644 --- a/dhat/dh_main.c +++ b/dhat/dh_main.c @@ -818,8 +818,11 @@ static void* dh_realloc ( ThreadId tid, void* p_old, SizeT new_szB ) return dh_malloc(tid, new_szB); } if (new_szB == 0) { - dh_free(tid, p_old); - return NULL; + if (VG_(clo_realloc_zero_bytes_frees) == True) { + dh_free(tid, p_old); + return NULL; + } + new_szB = 1; } return renew_block(tid, p_old, new_szB); } diff --git a/docs/xml/manual-core.xml b/docs/xml/manual-core.xml index 3a91c930fa..20886fe49e 100644 --- a/docs/xml/manual-core.xml +++ b/docs/xml/manual-core.xml @@ -1787,6 +1787,24 @@ that can report errors, e.g. Memcheck, but not Cachegrind.</para> </listitem> </varlistentry> + <varlistentry id="opt.realloc-zero-bytes-frees" xreflabel="--realloc-zero-bytes-frees"> + <term> + <option><![CDATA[--realloc-zero-bytes-frees=yes|no [default: yes for glibc no otherwise] ]]></option> + </term> + <listitem> + <para>The behaviour of <computeroutput>realloc()</computeroutput> is + implementation defined (in C17, in C23 it is likely to become + undefined). Valgrind tries to work in the same way as the + underlying OS and C runtime library. However, if you use a + different C runtime library then this default may be wrong. + For instance, if you use Valgrind on Linux installed via a package + and use the musl C runtime or the JEMalloc library then + consider using + <computeroutput>--realloc-zero-bytes-frees=no</computeroutput>. + </para> + </listitem> + </varlistentry> + </variablelist> <!-- end of xi:include in the manpage --> diff --git a/drd/drd_malloc_wrappers.c b/drd/drd_malloc_wrappers.c index 991fb845a0..b1be605832 100644 --- a/drd/drd_malloc_wrappers.c +++ b/drd/drd_malloc_wrappers.c @@ -184,8 +184,12 @@ static void* drd_realloc(ThreadId tid, void* p_old, SizeT new_size) if (new_size == 0) { - drd_free(tid, p_old); - return NULL; + if (VG_(clo_realloc_zero_bytes_frees) == True) + { + drd_free(tid, p_old); + return NULL; + } + new_size = 1; } s_cmalloc_n_mallocs++; diff --git a/drd/tests/memory_allocation.c b/drd/tests/memory_allocation.c index d6d6388236..ec8578514d 100644 --- a/drd/tests/memory_allocation.c +++ b/drd/tests/memory_allocation.c @@ -25,13 +25,12 @@ int main() * glibc returns a NULL pointer when the size argument passed to realloc() * is zero, while Darwin's C library returns a non-NULL pointer. Both are * allowed by POSIX. + * + * Other platforms also tend not to free. To make things simpler just + * free it if it is not NULL. */ -#if defined(VGO_darwin) if (p) free(p); -#else - assert(! p); -#endif } return 0; diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c index 26a37ead5e..cebc2bd2a1 100644 --- a/helgrind/hg_main.c +++ b/helgrind/hg_main.c @@ -4323,12 +4323,31 @@ static void* hg_cli__realloc ( ThreadId tid, void* payloadV, SizeT new_size ) if (((SSizeT)new_size) < 0) return NULL; + if (payloadV == NULL) { + return handle_alloc ( tid, new_size, VG_(clo_alignment), + /*is_zeroed*/False ); + } + md = (MallocMeta*) VG_(HT_lookup)( hg_mallocmeta_table, (UWord)payload ); if (!md) return NULL; /* apparently realloc-ing a bogus address. Oh well. */ tl_assert(md->payload == payload); + if (new_size == 0U ) { + if (VG_(clo_realloc_zero_bytes_frees) == True) { + md_tmp = VG_(HT_remove)( hg_mallocmeta_table, payload ); + tl_assert(md_tmp); + tl_assert(md_tmp == md); + + VG_(cli_free)((void*)md->payload); + delete_MallocMeta(md); + + return NULL; + } + new_size = 1U; + } + if (md->szB == new_size) { /* size unchanged */ md->where = VG_(record_ExeContext)(tid, 0); diff --git a/include/pub_tool_replacemalloc.h b/include/pub_tool_replacemalloc.h index f9f39b7d64..d59027f3e2 100644 --- a/include/pub_tool_replacemalloc.h +++ b/include/pub_tool_replacemalloc.h @@ -67,6 +67,8 @@ extern Bool VG_(clo_trace_malloc); /* Minimum alignment in functions that don't specify alignment explicitly. default: VG_MIN_MALLOC_SZB */ extern UInt VG_(clo_alignment); +/* Controls the behaviour of realloc(ptr, 0) */ +extern Bool VG_(clo_realloc_zero_bytes_frees); extern Bool VG_(replacement_malloc_process_cmd_line_option) ( const HChar* arg ); diff --git a/massif/ms_main.c b/massif/ms_main.c index 1ebbe4f29f..f3500c367d 100644 --- a/massif/ms_main.c +++ b/massif/ms_main.c @@ -1268,6 +1268,20 @@ void* realloc_block ( ThreadId tid, void* p_old, SizeT new_req_szB ) Xecu old_where; Bool is_ignored = False; + if (p_old == NULL) { + return alloc_and_record_block( tid, new_req_szB, VG_(clo_alignment), /*is_zeroed*/False ); + } + + if (new_req_szB == 0U) { + if (VG_(clo_realloc_zero_bytes_frees) == True) { + /* like ms_free */ + unrecord_block(p_old, /*maybe_snapshot*/True, /*exclude_first_entry*/True); + VG_(cli_free)(p_old); + return NULL; + } + new_req_szB = 1U; + } + // Remove the old block hc = VG_(HT_remove)(malloc_list, (UWord)p_old); if (hc == NULL) { diff --git a/massif/tests/realloc.post.exp b/massif/tests/realloc.post.exp index 779cfc16f7..c343c93b1b 100644 --- a/massif/tests/realloc.post.exp +++ b/massif/tests/realloc.post.exp @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- Command: ./realloc -Massif arguments: --stacks=no --heap-admin=0 --time-unit=B --threshold=0 --massif-out-file=massif.out --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook --ignore-fn=get_or_create_key_element +Massif arguments: --stacks=no --heap-admin=0 --time-unit=B --threshold=0 --massif-out-file=massif.out --realloc-zero-bytes-frees=yes --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook --ignore-fn=get_or_create_key_element ms_print arguments: --threshold=0 massif.out -------------------------------------------------------------------------------- diff --git a/massif/tests/realloc.vgtest b/massif/tests/realloc.vgtest index bdb38d839e..01e06f0853 100644 --- a/massif/tests/realloc.vgtest +++ b/massif/tests/realloc.vgtest @@ -1,5 +1,6 @@ prog: realloc -vgopts: -v -v --stats=yes --stacks=no --heap-admin=0 --time-unit=B --threshold=0 --massif-out-file=massif.out +# use --realloc-zero-bytes-frees=yes to get the same results on all platforms +vgopts: -v -v --stats=yes --stacks=no --heap-admin=0 --time-unit=B --threshold=0 --massif-out-file=massif.out --realloc-zero-bytes-frees=yes vgopts: --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook --ignore-fn=get_or_create_key_element stderr_filter: filter_verbose post: perl ../../massif/ms_print --threshold=0 massif.out | ../../tests/filter_addresses diff --git a/memcheck/docs/mc-manual.xml b/memcheck/docs/mc-manual.xml index e8f48d112d..414c3a2393 100644 --- a/memcheck/docs/mc-manual.xml +++ b/memcheck/docs/mc-manual.xml @@ -51,6 +51,11 @@ problems that are common in C and C++ programs.</para> allocation function.</para> </listitem> + <listitem> + <para>Using a <computeroutput>size</computeroutput> value of 0 + with realloc.</para> + </listitem> + <listitem> <para>Memory leaks.</para> </listitem> @@ -431,6 +436,28 @@ as "silly arguments" and no back-trace was included. </sect2> +<sect2 id="mc-manual.realocsizezero" + xreflabel="Realloc size zero"> +<title>Realloc size zero</title> + +<para>The (ab)use or realloc to also do the job of <function>free</function> +has been poorly understood for a long time. In the C17 standard +ISO/IEC 9899:2017] the behaviour of realloc when the size argument +is zero is specified as implementation defined. Memcheck warns about +the non-portable use or realloc.</para> + +<para>For example:</para> +<programlisting><![CDATA[ +==77609== realloc() with size 0 +==77609== at 0x48502B8: realloc (vg_replace_malloc.c:1450) +==77609== by 0x201989: main (realloczero.c:8) +==77609== Address 0x5464040 is 0 bytes inside a block of size 4 alloc'd +==77609== at 0x484CBB4: malloc (vg_replace_malloc.c:397) +==77609== by 0x201978: main (realloczero.c:7) +]]></programlisting> + +</sect2> + <sect2 id="mc-manual.leaks" xreflabel="Memory leak detection"> <title>Memory leak detection</title> diff --git a/memcheck/mc_errors.c b/memcheck/mc_errors.c index ee5533a632..00d6ec301e 100644 --- a/memcheck/mc_errors.c +++ b/memcheck/mc_errors.c @@ -75,6 +75,7 @@ typedef Err_Leak, Err_IllegalMempool, Err_FishyValue, + Err_ReallocSizeZero, } MC_ErrorTag; @@ -159,6 +160,10 @@ struct _MC_Error { AddrInfo ai; } FreeMismatch; + struct { + AddrInfo ai; + } ReallocSizeZero; + // Call to strcpy, memcpy, etc, with overlapping blocks. struct { Addr src; // Source block @@ -714,6 +719,21 @@ void MC_(pp_Error) ( const Error* err ) } break; + case Err_ReallocSizeZero: + if (xml) { + emit( " <kind>ReallocSizeZero</kind>\n" ); + emit( " <what>realloc() with size 0</what>\n" ); + VG_(pp_ExeContext)( VG_(get_error_where)(err) ); + VG_(pp_addrinfo_mc)(VG_(get_error_address)(err), + &extra->Err.ReallocSizeZero.ai, False); + } else { + emit( "realloc() with size 0\n" ); + VG_(pp_ExeContext)( VG_(get_error_where)(err) ); + VG_(pp_addrinfo_mc)(VG_(get_error_address)(err), + &extra->Err.ReallocSizeZero.ai, False); + } + break; + default: VG_(printf)("Error:\n unknown Memcheck error code %d\n", VG_(get_error_kind)(err)); @@ -868,6 +888,15 @@ void MC_(record_freemismatch_error) ( ThreadId tid, MC_Chunk* mc ) &extra ); } +void MC_(record_realloc_size_zero) ( ThreadId tid, Addr a ) +{ + MC_Error extra; + tl_assert(VG_INVALID_THREADID != tid); + extra.Err.ReallocSizeZero.ai.tag = Addr_Undescribed; + VG_(maybe_record_error)( tid, Err_ReallocSizeZero, a, /*s*/NULL, &extra ); +} + + void MC_(record_illegal_mempool_error) ( ThreadId tid, Addr a ) { MC_Error extra; @@ -1231,6 +1260,10 @@ UInt MC_(update_Error_extra)( const Error* err ) &extra->Err.FreeMismatch.ai ); return sizeof(MC_Error); } + case Err_ReallocSizeZero: + describe_addr ( ep, VG_(get_error_address)(err), + &extra->Err.ReallocSizeZero.ai ); + return sizeof(MC_Error); default: VG_(tool_panic)("mc_update_extra: bad errkind"); } @@ -1324,6 +1357,7 @@ typedef LeakSupp, // Something to be suppressed in a leak check. MempoolSupp, // Memory pool suppression. FishyValueSupp,// Fishy value suppression. + ReallocSizeZeroSupp, // realloc size 0 suppression } MC_SuppKind; @@ -1354,6 +1388,7 @@ Bool MC_(is_recognised_suppression) ( const HChar* name, Supp* su ) else if (VG_STREQ(name, "Value16")) skind = Value16Supp; else if (VG_STREQ(name, "Value32")) skind = Value32Supp; else if (VG_STREQ(name, "FishyValue")) skind = FishyValueSupp; + else if (VG_STREQ(name, "ReallocZero")) skind = ReallocSizeZeroSupp; else return False; @@ -1531,6 +1566,11 @@ Bool MC_(error_matches_suppression) ( const Error* err, const Supp* su ) supp_extra->argument_name); } + case ReallocSizeZeroSupp: { + + return (ekind == Err_ReallocSizeZero); + } + default: VG_(printf)("Error:\n" " unknown suppression type %d\n", @@ -1543,18 +1583,19 @@ Bool MC_(error_matches_suppression) ( const Error* err, const Supp* su ) const HChar* MC_(get_error_name) ( const Error* err ) { switch (VG_(get_error_kind)(err)) { - case Err_RegParam: return "Param"; - case Err_MemParam: return "Param"; - case Err_User: return "User"; - case Err_FreeMismatch: return "Free"; - case Err_IllegalMempool: return "Mempool"; - case Err_Free: return "Free"; - case Err_Jump: return "Jump"; - case Err_CoreMem: return "CoreMem"; - case Err_Overlap: return "Overlap"; - case Err_Leak: return "Leak"; - case Err_Cond: return "Cond"; - case Err_FishyValue: return "FishyValue"; + case Err_RegParam: return "Param"; + case Err_MemParam: return "Param"; + case Err_User: return "User"; + case Err_FreeMismatch: return "Free"; + case Err_IllegalMempool: return "Mempool"; + case Err_Free: return "Free"; + case Err_Jump: return "Jump"; + case Err_CoreMem: return "CoreMem"; + case Err_Overlap: return "Overlap"; + case Err_Leak: return "Leak"; + case Err_Cond: return "Cond"; + case Err_FishyValue: return "FishyValue"; + case Err_ReallocSizeZero: return "ReallocZero"; case Err_Addr: { MC_Error* extra = VG_(get_error_extra)(err); switch ( extra->Err.Addr.szB ) { diff --git a/memcheck/mc_include.h b/memcheck/mc_include.h index 30d0affdb2..3c1b1a7cd4 100644 --- a/memcheck/mc_include.h +++ b/memcheck/mc_include.h @@ -555,6 +555,7 @@ void MC_(record_jump_error) ( ThreadId tid, Addr a ); void MC_(record_free_error) ( ThreadId tid, Addr a ); void MC_(record_illegal_mempool_error) ( ThreadId tid, Addr a ); void MC_(record_freemismatch_error) ( ThreadId tid, MC_Chunk* mc ); +void MC_(record_realloc_size_zero) ( ThreadId tid, Addr a ); void MC_(record_overlap_error) ( ThreadId tid, const HChar* function, Addr src, Addr dst, SizeT szB ); @@ -727,6 +728,9 @@ extern Int MC_(clo_mc_level); /* Should we show mismatched frees? Default: YES */ extern Bool MC_(clo_show_mismatched_frees); +/* Should we warn about deprecated realloc() of size 0 ? Default : YES */ +extern Bool MC_(clo_show_realloc_size_zero); + /* Indicates the level of detail for Vbit tracking through integer add, subtract, and some integer comparison operations. */ typedef diff --git a/memcheck/mc_main.c b/memcheck/mc_main.c index 8efd7cb40c..3619dd1f92 100644 --- a/memcheck/mc_main.c +++ b/memcheck/mc_main.c @@ -6064,6 +6064,7 @@ Int MC_(clo_free_fill) = -1; KeepStacktraces MC_(clo_keep_stacktraces) = KS_alloc_and_free; Int MC_(clo_mc_level) = 2; Bool MC_(clo_show_mismatched_frees) = True; +Bool MC_(clo_show_realloc_size_zero) = True; ExpensiveDefinednessChecks MC_(clo_expensive_definedness_checks) = EdcAUTO; @@ -6256,6 +6257,8 @@ static Bool mc_process_cmd_line_options(const HChar* arg) else if VG_BOOL_CLOM(cloPD, arg, "--show-mismatched-frees", MC_(clo_show_mismatched_frees)) {} + else if VG_BOOL_CLOM(cloPD, arg, "--show-realloc-size-zero", + MC_(clo_show_realloc_size_zero)) {} else if VG_XACT_CLO(arg, "--expensive-definedness-checks=no", MC_(clo_expensive_definedness_checks), EdcNO) {} @@ -6320,6 +6323,7 @@ static void mc_print_usage(void) " --keep-stacktraces=alloc|free|alloc-and-free|alloc-then-free|none\n" " stack trace(s) to keep for malloc'd/free'd areas [alloc-and-free]\n" " --show-mismatched-frees=no|yes show frees that don't match the allocator? [yes]\n" +" --show-realloc-size-zero=no|yes show realocs with a size of zero? [yes]\n" ); } diff --git a/memcheck/mc_malloc_wrappers.c b/memcheck/mc_malloc_wrappers.c index d6775bd1d3..87cf4d8f54 100644 --- a/memcheck/mc_malloc_wrappers.c +++ b/memcheck/mc_malloc_wrappers.c @@ -573,6 +573,25 @@ void* MC_(realloc) ( ThreadId tid, void* p_old, SizeT new_szB ) if (MC_(record_fishy_value_error)(tid, "realloc", "size", new_szB)) return NULL; + if (p_old == NULL) { + return MC_(new_block) ( tid, 0, new_szB, VG_(clo_alignment), + /*is_zeroed*/False, MC_AllocMalloc, MC_(malloc_list)); + } + + if (new_szB == 0U) { + if (MC_(clo_show_realloc_size_zero)) { + MC_(record_realloc_size_zero)(tid, (Addr)p_old); + } + + if (VG_(clo_realloc_zero_bytes_frees) == True) { + MC_(handle_free)( + tid, (Addr)p_old, MC_(Malloc_Redzone_SzB), MC_AllocMalloc ); + + return NULL; + } + new_szB = 1U; + } + cmalloc_n_frees ++; cmalloc_n_mallocs ++; cmalloc_bs_mallocd += (ULong)new_szB; diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index a3b9332b53..7600981687 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -286,6 +286,21 @@ EXTRA_DIST = \ reach_thread_register.stderr.exp reach_thread_register.vgtest \ reach_thread_register.stderr.exp-mips32 \ reach_thread_register.stderr.exp-mips64 \ + realloc_size_zero.stderr.exp realloc_size_zero.stdout.exp-glibc \ + realloc_size_zero.stdout.exp-other \ + realloc_size_zero.vgtest \ + realloc_size_zero_yes.stderr.exp realloc_size_zero_yes.stdout.exp \ + realloc_size_zero_yes.vgtest \ + realloc_size_zero_no.stderr.exp realloc_size_zero_no.stdout.exp \ + realloc_size_zero_no.vgtest \ + realloc_size_zero_off.stderr.exp realloc_size_zero_off.stdout.exp \ + realloc_size_zero_off.vgtest \ + realloc_size_zero_mismatch.stderr.exp \ + realloc_size_zero_mismatch.stdout.exp \ + realloc_size_zero_mismatch.vgtest \ + realloc_size_zero_supp.stderr.exp realloc_size_zero_supp.stdout.exp \ + realloc_size_zero_supp.vgtest \ + realloc_size_zero.supp \ realloc1.stderr.exp realloc1.vgtest \ realloc2.stderr.exp realloc2.vgtest \ realloc3.stderr.exp realloc3.vgtest \ @@ -442,6 +457,7 @@ check_PROGRAMS = \ pipe pointer-trace \ posix_memalign \ post-syscall \ + realloc_size_zero realloc_size_zero_mismatch \ realloc1 realloc2 realloc3 \ recursive-merge \ resvn_stack \ @@ -636,6 +652,8 @@ partial_load_CFLAGS = $(AM_CFLAGS) @FLAG_W_NO_USE_AFTER_FREE@ reach_thread_register_CFLAGS = $(AM_CFLAGS) -O2 reach_thread_register_LDADD = -lpthread +realloc_size_zero_mismatch_SOURCES = realloc_size_zero_mismatch.cpp + resvn_stack_CFLAGS = $(AM_CFLAGS) @FLAG_W_NO_UNINITIALIZED@ sendmsg_CFLAGS = $(AM_CFLAGS) diff --git a/memcheck/tests/amd64-freebsd/reallocf.c b/memcheck/tests/amd64-freebsd/reallocf.c index 043d0d6d7a..04ab4ccfce 100644 --- a/memcheck/tests/amd64-freebsd/reallocf.c +++ b/memcheck/tests/amd64-freebsd/reallocf.c @@ -10,6 +10,7 @@ int main(void) pi = reallocf(pi, 10*sizeof(int)); VALGRIND_DO_ADDED_LEAK_CHECK; pi = reallocf(pi, 0); + free(pi); VALGRIND_DO_CHANGED_LEAK_CHECK; pi = NULL; pi = realloc(pi, 10*sizeof(int)); diff --git a/memcheck/tests/amd64-freebsd/reallocf.stderr.exp b/memcheck/tests/amd64-freebsd/reallocf.stderr.exp index b3e6658b78..4ec2f2ef01 100644 --- a/memcheck/tests/amd64-freebsd/reallocf.stderr.exp +++ b/memcheck/tests/amd64-freebsd/reallocf.stderr.exp @@ -10,6 +10,13 @@ LEAK SUMMARY: Reachable blocks (those to which a pointer was found) are not shown. To see them, rerun with: --leak-check=full --show-leak-kinds=all +realloc() with size 0 + at 0x........: reallocf (vg_replace_malloc.c:...) + by 0x........: main (reallocf.c:12) + Address 0x........ is 0 bytes inside a block of size 40 alloc'd + at 0x........: reallocf (vg_replace_malloc.c:...) + by 0x........: main (reallocf.c:10) + All heap blocks were freed -- no leaks are possible LEAK SUMMARY: @@ -26,9 +33,9 @@ All heap blocks were freed -- no leaks are possible HEAP SUMMARY: in use at exit: 0 bytes in 0 blocks - total heap usage: 3 allocs, 3 frees, 562,949,953,421,392 bytes allocated + total heap usage: 4 allocs, 4 frees, 562,949,953,421,393 bytes allocated For a detailed leak analysis, rerun with: --leak-check=full For lists of detected and suppressed errors, rerun with: -s -ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) diff --git a/memcheck/tests/freebsd/static_allocs.stderr.exp b/memcheck/tests/freebsd/static_allocs.stderr.exp index 132976cbb6..b6e6d328d5 100644 --- a/memcheck/tests/freebsd/static_allocs.stderr.exp +++ b/memcheck/tests/freebsd/static_allocs.stderr.exp @@ -1,5 +1,15 @@ +realloc() with size 0 + at 0x........: reallocf (vg_replace_malloc.c:...) + by 0x........: main (static_allocs.c:36) + Address 0x........ is 0 bytes inside a block of size 160 alloc'd + at 0x........: calloc (vg_replace_malloc.c:...) + by 0x........: main (static_allocs.c:35) + +1 bytes in 1 blocks are definitely lost in loss record ... of ... + at 0x........: reallocf (vg_replace_malloc.c:...) + by 0x........: main (static_allocs.c:36) + 10 bytes in 1 blocks are definitely lost in loss record ... of ... - at 0x........: malloc (vg_replace_malloc.c:...) - by 0x........: realloc (vg_replace_malloc.c:...) + at 0x........: realloc (vg_replace_malloc.c:...) by 0x........: main (static_allocs.c:34) diff --git a/memcheck/tests/realloc_size_zero.c b/memcheck/tests/realloc_size_zero.c new file mode 100644 index 0000000000..afe2a76680 --- /dev/null +++ b/memcheck/tests/realloc_size_zero.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> + +int main(void) +{ + int i; + char* p = malloc(1024); + p[0] = '\0'; + errno = 0; + p = realloc(p, 0); + if (p) { + printf("p not NULL after realloc 0\n"); + } else { + printf("p is NULL after realloc 0\n"); + } + if (errno) { + perror("realloc(something, 0):"); + } + if (p) { + free(p); + } + + errno = 0; + volatile void *ptr = NULL; + volatile size_t size = 0U; + char *p2 = realloc(ptr, size); + if (p2) { + printf("p2 not NULL after realloc 0\n"); + } else { + printf("p2 is NULL after realloc 0\n"); + } + if (errno) { + perror("realloc(NULL, 0):"); + } + if (p2) { + free(p2); + } +} diff --git a/memcheck/tests/realloc_size_zero.stderr.exp b/memcheck/tests/realloc_size_zero.stderr.exp new file mode 100644 index 0000000000..6204deecdd --- /dev/null +++ b/memcheck/tests/realloc_size_zero.stderr.exp @@ -0,0 +1,7 @@ +realloc() with size 0 + at 0x........: realloc (vg_replace_malloc.c:...) + by 0x........: main (realloc_size_zero.c:11) + Address 0x........ is 0 bytes inside a block of size 1,024 alloc'd + at 0x........: malloc (vg_replace_malloc.c:...) + by 0x........: main (realloc_size_zero.c:8) + diff --git a/memcheck/tests/realloc_size_zero.stdout.exp-glibc b/memcheck/tests/realloc_size_zero.stdout.exp-glibc new file mode 100644 index 0000000000..ed2bcf0cd4 --- /dev/null +++ b/memcheck/tests/realloc_size_zero.stdout.exp-glibc @@ -0,0 +1,2 @@ +p is NULL after realloc 0 +p2 not NULL after realloc 0 diff --git a/memcheck/tests/realloc_size_zero.stdout.exp-other b/memcheck/tests/realloc_size_zero.stdout.exp-other new file mode 100644 index 0000000000..103f1d5ebc --- /dev/null +++ b/memcheck/tests/realloc_size_zero.stdout.exp-other @@ -0,0 +1,2 @@ +p not NULL after realloc 0 +p2 not NULL after realloc 0 diff --git a/memcheck/tests/realloc_size_zero.supp b/memcheck/tests/realloc_size_zero.supp new file mode 100644 index 0000000000..42e5f8d811 --- /dev/null +++ b/memcheck/tests/realloc_size_zero.supp @@ -0,0 +1,7 @@ +{ + Test for realoc zero suppression + Memcheck:ReallocZero + fun:realloc + fun:main +} + diff --git a/memcheck/tests/realloc_size_zero.vgtest b/memcheck/tests/realloc_size_zero.vgtest new file mode 100644 index 0000000000..e39d9c0725 --- /dev/null +++ b/memcheck/tests/realloc_size_zero.vgtest @@ -0,0 +1,2 @@ +prog: realloc_size_zero +vgopts: -q diff --git a/memcheck/tests/realloc_size_zero_mismatch.cpp b/memcheck/tests/realloc_size_zero_mismatch.cpp new file mode 100644 index 0000000000..13d1e58832 --- /dev/null +++ b/memcheck/tests/realloc_size_zero_mismatch.cpp @@ -0,0 +1,41 @@ +#include <iostream> +#include <cstdlib> +#include <cerrno> + +using std::realloc; +using std::cout; +using std::perror; + +int main(void) +{ + char* p = new char[1024]; + p[0] = '\0'; + errno = 0; + // mismatch + p = static_cast<char *>(realloc(p, 0)); + if (p) { + cout << "p not nullptr after realloc 0\n"; + } else { + cout << "p is nullptr after realloc 0\n"; + } + if (errno) { + perror("realloc(something, 0):"); + } + // mismatch again + delete [] p; + + errno = 0; + volatile void *ptr = NULL; + volatile size_t size = 0U; + char *p2 = static_cast<char *>(realloc(const_cast<void*>(ptr), size)); + if (p2) { + cout << "p2 not nullptr after realloc 0\n"; + } else { + cout << "p2 is nullptr after realloc 0\n"; + } + if (errno) { + perror("realloc(NULL, 0):"); + } + // mismatch + delete [] p2; +} diff --git a/memcheck/tests/realloc_size_zero_mismatch.stderr.exp b/memcheck/tests/realloc_size_zero_mismatch.stderr.exp new file mode 100644 index 0000000000..f7c535574b --- /dev/null +++ b/memcheck/tests/realloc_size_zero_mismatch.stderr.exp @@ -0,0 +1,28 @@ +realloc() with size 0 + at 0x........: realloc (vg_replace_malloc.c:...) + by 0x........: main (realloc_size_zero_mismatch.cpp:15) + Address 0x........ is 0 bytes inside a block of size 1,024 alloc'd + at 0x........: ...operator new[]... (vg_replace_malloc.c:...) + by 0x........: main (realloc_size_zero_mismatch.cpp:11) + +Mismatched free() / delete / delete [] + at 0x........: realloc (vg_replace_malloc.c:...) + by 0x........: main (realloc_size_zero_mismatch.cpp:15) + Address 0x........ is 0 bytes inside a block of size 1,024 alloc'd + at 0x........: ...operator new[]... (vg_replace_malloc.c:...) + by 0x........: main (realloc_size_zero_mismatch.cpp:11) + +Mismatched free() / delete / delete [] + at 0x........: ...operator delete[]... (vg_replace_malloc.c:...) + by 0x........: main (realloc_size_zero_mismatch.cpp:25) + Address 0x........ is 0 bytes inside a block of size 1 alloc'd + at 0x........: realloc (vg_replace_malloc.c:...) + by 0x........: main (realloc_size_zero_mismatch.cpp:15) + +Mismatched free() / delete / delete [] + at 0x........: ...operator delete[]... (vg_replace_malloc.c:...) + by 0x........: main (realloc_size_zero_mismatch.cpp:40) + Address 0x........ is 0 bytes after a block of size 0 alloc'd + at 0x........: realloc (vg_replace_malloc.c:...) + by 0x........: main (realloc_size_zero_mismatch.cpp:30) + diff --git a/memcheck/tests/realloc_size_zero_mismatch.stdout.exp b/memcheck/tests/realloc_size_zero_mismatch.stdout.exp new file mode 100644 index 0000000000..60b2ebd9e6 --- /dev/null +++ b/memcheck/tests/realloc_size_zero_mismatch.stdout.exp @@ -0,0 +1,2 @@ +p not nullptr after realloc 0 +p2 not nullptr after realloc 0 diff --git a/memcheck/tests/realloc_size_zero_mismatch.vgtest b/memcheck/tests/realloc_size_zero_mismatch.vgtest new file mode 100644 index 0000000000..4aad69190e --- /dev/null +++ b/memcheck/tests/realloc_size_zero_mismatch.vgtest @@ -0,0 +1,2 @@ +prog: realloc_size_zero_mismatch +vgopts: -q --realloc-zero-bytes-frees=no diff --git a/memcheck/tests/realloc_size_zero_no.stderr.exp b/memcheck/tests/realloc_size_zero_no.stderr.exp new file mode 100644 index 0000000000..00ffada247 --- /dev/null +++ b/memcheck/tests/realloc_size_zero_no.stderr.exp @@ -0,0 +1,7 @@ +realloc() with size 0 + at 0x........: realloc (vg_replace_malloc.c:...) + ... + Address 0x........ is 0 bytes inside a block of size 1,024 alloc'd + at 0x........: malloc (vg_replace_malloc.c:...) + ... + diff --git a/memcheck/tests/realloc_size_zero_no.stdout.exp b/memcheck/tests/realloc_size_zero_no.stdout.exp new file mode 100644 index 0000000000..103f1d5ebc --- /dev/null +++ b/memcheck/tests/realloc_size_zero_no.stdout.exp @@ -0,0 +1,2 @@ +p not NULL after realloc 0 +p2 not NULL after realloc 0 diff --git a/memcheck/tests/realloc_size_zero_no.vgtest b/memcheck/tests/realloc_size_zero_no.vgtest new file mode 100644 index 0000000000..80bf9e53d6 --- /dev/null +++ b/memcheck/tests/realloc_size_zero_no.vgtest @@ -0,0 +1,2 @@ +prog: realloc_size_zero +vgopts: -q --realloc-zero-bytes-frees=no diff --git a/memcheck/tests/realloc_size_zero_off.stderr.exp b/memcheck/tests/realloc_size_zero_off.stderr.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/memcheck/tests/realloc_size_zero_off.stdout.exp b/memcheck/tests/realloc_size_zero_off.stdout.exp new file mode 100644 index 0000000000..103f1d5ebc --- /dev/null +++ b/memcheck/tests/realloc_size_zero_off.stdout.exp @@ -0,0 +1,2 @@ +p not NULL after realloc 0 +p2 not NULL after realloc 0 diff --git a/memcheck/tests/realloc_size_zero_off.vgtest b/memcheck/tests/realloc_size_zero_off.vgtest new file mode 100644 index 0000000000..a376ce755f --- /dev/null +++ b/memcheck/tests/realloc_size_zero_off.vgtest @@ -0,0 +1,2 @@ +prog: realloc_size_zero +vgopts: -q --realloc-zero-bytes-frees=no --show-realloc-size-zero=no diff --git a/memcheck/tests/realloc_size_zero_supp.stderr.exp b/memcheck/tests/realloc_size_zero_supp.stderr.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/memcheck/tests/realloc_size_zero_supp.stdout.exp b/memcheck/tests/realloc_size_zero_supp.stdout.exp new file mode 100644 index 0000000000..103f1d5ebc --- /dev/null +++ b/memcheck/tests/realloc_size_zero_supp.stdout.exp @@ -0,0 +1,2 @@ +p not NULL after realloc 0 +p2 not NULL after realloc 0 diff --git a/memcheck/tests/realloc_size_zero_supp.vgtest b/memcheck/tests/realloc_size_zero_supp.vgtest new file mode 100644 index 0000000000..ea8886deb1 --- /dev/null +++ b/memcheck/tests/realloc_size_zero_supp.vgtest @@ -0,0 +1,2 @@ +prog: realloc_size_zero +vgopts: -q --realloc-zero-bytes-frees=no --suppressions=realloc_size_zero.supp diff --git a/memcheck/tests/realloc_size_zero_yes.stderr.exp b/memcheck/tests/realloc_size_zero_yes.stderr.exp new file mode 100644 index 0000000000..00ffada247 --- /dev/null +++ b/memcheck/tests/realloc_size_zero_yes.stderr.exp @@ -0,0 +1,7 @@ +realloc() with size 0 + at 0x........: realloc (vg_replace_malloc.c:...) + ... + Address 0x........ is 0 bytes inside a block of size 1,024 alloc'd + at 0x........: malloc (vg_replace_malloc.c:...) + ... + diff --git a/memcheck/tests/realloc_size_zero_yes.stdout.exp b/memcheck/tests/realloc_size_zero_yes.stdout.exp new file mode 100644 index 0000000000..ed2bcf0cd4 --- /dev/null +++ b/memcheck/tests/realloc_size_zero_yes.stdout.exp @@ -0,0 +1,2 @@ +p is NULL after realloc 0 +p2 not NULL after realloc 0 diff --git a/memcheck/tests/realloc_size_zero_yes.vgtest b/memcheck/tests/realloc_size_zero_yes.vgtest new file mode 100644 index 0000000000..16310f2a95 --- /dev/null +++ b/memcheck/tests/realloc_size_zero_yes.vgtest @@ -0,0 +1,2 @@ +prog: realloc_size_zero +vgopts: -q --realloc-zero-bytes-frees=yes diff --git a/none/tests/cmdline1.stdout.exp b/none/tests/cmdline1.stdout.exp index c3e91bfcde..3b6c116094 100644 --- a/none/tests/cmdline1.stdout.exp +++ b/none/tests/cmdline1.stdout.exp @@ -154,6 +154,10 @@ usage: valgrind [options] prog-and-args attempt to avoid expensive address-space-resync operations --max-threads=<number> maximum number of threads that valgrind can handle [500] + --realloc-zero-bytes-frees=yes|no [yes on Linux glibc, no otherwise] + should calls to realloc with a size of 0 + free memory and return NULL or + allocate/resize and return non-NULL user options for Nulgrind: (none) diff --git a/none/tests/cmdline1.stdout.exp-non-linux b/none/tests/cmdline1.stdout.exp-non-linux index c0e71fa576..e67183efe4 100644 --- a/none/tests/cmdline1.stdout.exp-non-linux +++ b/none/tests/cmdline1.stdout.exp-non-linux @@ -152,6 +152,10 @@ usage: valgrind [options] prog-and-args attempt to avoid expensive address-space-resync operations --max-threads=<number> maximum number of threads that valgrind can handle [500] + --realloc-zero-bytes-frees=yes|no [yes on Linux glibc, no otherwise] + should calls to realloc with a size of 0 + free memory and return NULL or + allocate/resize and return non-NULL user options for Nulgrind: (none) diff --git a/none/tests/cmdline2.stdout.exp b/none/tests/cmdline2.stdout.exp index 3158c267a9..241d33afa5 100644 --- a/none/tests/cmdline2.stdout.exp +++ b/none/tests/cmdline2.stdout.exp @@ -154,6 +154,10 @@ usage: valgrind [options] prog-and-args attempt to avoid expensive address-space-resync operations --max-threads=<number> maximum number of threads that valgrind can handle [500] + --realloc-zero-bytes-frees=yes|no [yes on Linux glibc, no otherwise] + should calls to realloc with a size of 0 + free memory and return NULL or + allocate/resize and return non-NULL user options for Nulgrind: (none) diff --git a/none/tests/cmdline2.stdout.exp-non-linux b/none/tests/cmdline2.stdout.exp-non-linux index c19fa72597..63af17bf74 100644 --- a/none/tests/cmdline2.stdout.exp-non-linux +++ b/none/tests/cmdline2.stdout.exp-non-linux @@ -152,6 +152,10 @@ usage: valgrind [options] prog-and-args attempt to avoid expensive address-space-resync operations --max-threads=<number> maximum number of threads that valgrind can handle [500] + --realloc-zero-bytes-frees=yes|no [yes on Linux glibc, no otherwise] + should calls to realloc with a size of 0 + free memory and return NULL or + allocate/resize and return non-NULL user options for Nulgrind: (none) |
|
From: Paul F. <pa...@so...> - 2023-03-10 17:42:08
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=4af62304d95701ed110f4ba89c5a9ceeb0255393 commit 4af62304d95701ed110f4ba89c5a9ceeb0255393 Author: Paul Floyd <pj...@wa...> Date: Fri Mar 10 18:41:26 2023 +0100 Rename memcheck/tests/sized_aligned_new_delete_args.stderr.exp-glibc It's for GCC / libstdc++ really Diff: --- memcheck/tests/Makefile.am | 2 +- ...gs.stderr.exp-glibc => sized_aligned_new_delete_args.stderr.exp-gcc} | 0 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index 70c0a46d58..a3b9332b53 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -142,7 +142,7 @@ EXTRA_DIST = \ sized_aligned_new_delete_args.stderr.exp \ sized_aligned_new_delete_args.vgtest \ sized_aligned_new_delete_args.stderr.exp_32 \ - sized_aligned_new_delete_args.stderr.exp-glibc \ + sized_aligned_new_delete_args.stderr.exp-gcc \ sized_aligned_new_delete_misaligned.stderr.exp \ sized_aligned_new_delete_misaligned.vgtest \ deep-backtrace.vgtest deep-backtrace.stderr.exp \ diff --git a/memcheck/tests/sized_aligned_new_delete_args.stderr.exp-glibc b/memcheck/tests/sized_aligned_new_delete_args.stderr.exp-gcc similarity index 100% rename from memcheck/tests/sized_aligned_new_delete_args.stderr.exp-glibc rename to memcheck/tests/sized_aligned_new_delete_args.stderr.exp-gcc |
|
From: Paul F. <pa...@so...> - 2023-03-10 17:40:10
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=c2a0cd6e11670a80975bb83a740a006233f58075 commit c2a0cd6e11670a80975bb83a740a006233f58075 Author: Paul Floyd <pj...@wa...> Date: Fri Mar 10 18:39:05 2023 +0100 darwin regtest: fix unused variable warning Copied and paster from old posix_memalign test Diff: --- memcheck/tests/darwin/aligned_alloc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/memcheck/tests/darwin/aligned_alloc.c b/memcheck/tests/darwin/aligned_alloc.c index f8d580538f..1c2fdb78cb 100644 --- a/memcheck/tests/darwin/aligned_alloc.c +++ b/memcheck/tests/darwin/aligned_alloc.c @@ -4,7 +4,6 @@ int main(void) { char* p = NULL; - int res; // zero size p = aligned_alloc(0, 8); |
|
From: Paul F. <pa...@so...> - 2023-03-10 07:42:30
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=28e4efb2b11afa79249fd72e49f20524e900e497 commit 28e4efb2b11afa79249fd72e49f20524e900e497 Author: Paul Floyd <pj...@wa...> Date: Fri Mar 10 08:40:40 2023 +0100 Mised one aligned alloc wrapper on Linux Need different expected for GCC / libstdc++ And I think that the 32bit expected will also need updating. Diff: --- coregrind/m_replacemalloc/vg_replace_malloc.c | 2 +- memcheck/tests/Makefile.am | 1 + .../sized_aligned_new_delete_args.stderr.exp-glibc | 80 ++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 8781645e85..3379aa96f7 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -1073,7 +1073,7 @@ extern int *___errno (void) __attribute__((weak)); DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); // operator delete(void*, unsigned int, std::align_val_t), GNU mangling #if __SIZEOF_SIZE_T__ == 4 diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index c9008ec5e7..70c0a46d58 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -142,6 +142,7 @@ EXTRA_DIST = \ sized_aligned_new_delete_args.stderr.exp \ sized_aligned_new_delete_args.vgtest \ sized_aligned_new_delete_args.stderr.exp_32 \ + sized_aligned_new_delete_args.stderr.exp-glibc \ sized_aligned_new_delete_misaligned.stderr.exp \ sized_aligned_new_delete_misaligned.vgtest \ deep-backtrace.vgtest deep-backtrace.stderr.exp \ diff --git a/memcheck/tests/sized_aligned_new_delete_args.stderr.exp-glibc b/memcheck/tests/sized_aligned_new_delete_args.stderr.exp-glibc new file mode 100644 index 0000000000..03eded9016 --- /dev/null +++ b/memcheck/tests/sized_aligned_new_delete_args.stderr.exp-glibc @@ -0,0 +1,80 @@ +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:16) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:16) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:17) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:19) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:19) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:20) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:24) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:24) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:24) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:25) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:27) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:27) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:27) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:28) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: ...operator delete... (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:31) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, unsigned long) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:34) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:37) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:37) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:40) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:40) + |
|
From: Paul F. <pa...@so...> - 2023-03-09 19:59:59
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=f6ee38b419ee0e26e39fcf4a528ca60e3e5802d2 commit f6ee38b419ee0e26e39fcf4a528ca60e3e5802d2 Author: Paul Floyd <pj...@wa...> Date: Thu Mar 9 20:58:12 2023 +0100 Malloc replacements: add some C++14/17 comments Rearrange the code to group C++ 14 operator deeltes together. Diff: --- coregrind/m_replacemalloc/vg_replace_malloc.c | 124 +++++++++++++++++--------- 1 file changed, 80 insertions(+), 44 deletions(-) diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 05bc9a4f61..8781645e85 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -114,6 +114,23 @@ mid-06: could be improved, since we can now intercept in the main executable too. + + 2023-03: + + There seem to be an ever increasing number of C++ new and delete + oveloads. + + See + https://en.cppreference.com/w/cpp/memory/new/operator_new + https://en.cppreference.com/w/cpp/memory/new/operator_delete + + We need to redirect the "replaceable" versions. + + Anything "user-defined" or "class-specific" we can't know + about and the user needs to use memory pool annotation. + + "non-alocating placement" as the name implies does not + allocate. Placement deletes are no-ops. */ @@ -938,6 +955,35 @@ extern int *___errno (void) __attribute__((weak)); /*---------------------- delete ----------------------*/ +#if defined(VGO_linux) + // operator delete(void*), not mangled (for gcc 2.96) + FREE(VG_Z_LIBSTDCXX_SONAME, __builtin_delete, __builtin_delete ); + FREE(VG_Z_LIBC_SONAME, __builtin_delete, __builtin_delete ); + // operator delete(void*), GNU mangling + FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete ); + FREE(VG_Z_LIBCXX_SONAME, _ZdlPv, __builtin_delete ); + FREE(VG_Z_LIBC_SONAME, _ZdlPv, __builtin_delete ); + FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete ); + +#elif defined(VGO_freebsd) + FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete ); + FREE(VG_Z_LIBCXX_SONAME, _ZdlPv, __builtin_delete ); + FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete ); + +#elif defined(VGO_darwin) + // operator delete(void*), GNU mangling + //FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete ); + //FREE(VG_Z_LIBC_SONAME, _ZdlPv, __builtin_delete ); + +#elif defined(VGO_solaris) + // operator delete(void*), GNU mangling + FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete ); + FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete ); + +#endif + + /*------------------- C++14 delete sized -------------------*/ + #define DELETE_SIZED(soname, fnname, vg_replacement) \ \ void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, SizeT size); \ @@ -952,21 +998,13 @@ extern int *___errno (void) __attribute__((weak)); } #if defined(VGO_linux) - // operator delete(void*), not mangled (for gcc 2.96) - FREE(VG_Z_LIBSTDCXX_SONAME, __builtin_delete, __builtin_delete ); - FREE(VG_Z_LIBC_SONAME, __builtin_delete, __builtin_delete ); - // operator delete(void*), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPv, __builtin_delete ); - FREE(VG_Z_LIBC_SONAME, _ZdlPv, __builtin_delete ); - FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete ); - // operator delete(void*, unsigned int), C++14, GNU mangling + // operator delete(void*, unsigned int) #if __SIZEOF_SIZE_T__ == 4 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete ); DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete ); DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdlPvj, __builtin_delete ); DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete ); - // operator delete(void*, unsigned long), C++14, GNU mangling + // operator delete(void*, unsigned long) #elif __SIZEOF_SIZE_T__ == 8 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete ); DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete ); @@ -974,33 +1012,23 @@ extern int *___errno (void) __attribute__((weak)); DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete ); #endif - #elif defined(VGO_freebsd) - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPv, __builtin_delete ); - FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete ); - // operator delete(void*, unsigned long), C++14, GNU mangling + // operator delete(void*, unsigned int) #if __SIZEOF_SIZE_T__ == 4 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete ); DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete ); DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete ); #elif __SIZEOF_SIZE_T__ == 8 + // operator delete(void*, unsigned long) DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete ); DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete ); DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete ); #endif #elif defined(VGO_darwin) - // operator delete(void*), GNU mangling - //FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete ); - //FREE(VG_Z_LIBC_SONAME, _ZdlPv, __builtin_delete ); #elif defined(VGO_solaris) - // operator delete(void*), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPv, __builtin_delete ); - FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete ); - - // operator delete(void*, unsigned long), C++14, GNU mangling + // operator delete(void*, unsigned long) #if __SIZEOF_SIZE_T__ == 4 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete ); DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete ); @@ -1009,7 +1037,6 @@ extern int *___errno (void) __attribute__((weak)); DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete ); #endif - #endif /*------------------- C++17 delete aligned -------------------*/ @@ -1168,7 +1195,31 @@ extern int *___errno (void) __attribute__((weak)); FREE(VG_Z_LIBC_SONAME, _ZdaPv, __builtin_vec_delete ); FREE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete ); -// operator delete[](void*, unsigned long), C++14, GNU mangling +#elif defined(VGO_freebsd) + // operator delete[](void*), GNU mangling + FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete ); + FREE(VG_Z_LIBCXX_SONAME, _ZdaPv, __builtin_vec_delete ); + FREE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete ); + +#elif defined(VGO_darwin) + // operator delete[](void*), not mangled (for gcc 2.96) + //FREE(VG_Z_LIBSTDCXX_SONAME, __builtin_vec_delete, __builtin_vec_delete ); + //FREE(VG_Z_LIBC_SONAME, __builtin_vec_delete, __builtin_vec_delete ); + // operator delete[](void*), GNU mangling + //FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete ); + //FREE(VG_Z_LIBC_SONAME, _ZdaPv, __builtin_vec_delete ); + +#elif defined(VGO_solaris) + // operator delete[](void*), GNU mangling + FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete ); + FREE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete ); + +#endif + +/*---------------------- C++14 delete sized [] ----------------------*/ + +#if defined(VGO_linux) +// operator delete[](void*, unsigned int) #if __SIZEOF_SIZE_T__ == 4 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); @@ -1183,11 +1234,7 @@ extern int *___errno (void) __attribute__((weak)); #endif #elif defined(VGO_freebsd) - // operator delete[](void*), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPv, __builtin_vec_delete ); - FREE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete ); - // operator delete[](void*, unsigned long), C++14, GNU mangling + // operator delete[](void*, unsigned int) #if __SIZEOF_SIZE_T__ == 4 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); @@ -1199,23 +1246,13 @@ extern int *___errno (void) __attribute__((weak)); #endif #elif defined(VGO_darwin) - // operator delete[](void*), not mangled (for gcc 2.96) - //FREE(VG_Z_LIBSTDCXX_SONAME, __builtin_vec_delete, __builtin_vec_delete ); - //FREE(VG_Z_LIBC_SONAME, __builtin_vec_delete, __builtin_vec_delete ); - // operator delete[](void*), GNU mangling - //FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete ); - //FREE(VG_Z_LIBC_SONAME, _ZdaPv, __builtin_vec_delete ); #elif defined(VGO_solaris) - // operator delete[](void*), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPv, __builtin_vec_delete ); - FREE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete ); - - // operator delete[](void*, unsigned int), C++14, GNU mangling + // operator delete[](void*, unsigned int) #if __SIZEOF_SIZE_T__ == 4 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete ); - // operator delete[](void*, unsigned long), C++14, GNU mangling + // operator delete[](void*, unsigned long) #elif __SIZEOF_SIZE_T__ == 8 DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete ); DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete ); @@ -1608,7 +1645,6 @@ extern int *___errno (void) __attribute__((weak)); #endif - #if defined(VGO_linux) && !defined(MUSL_LIBC) #define MEMALIGN(soname, fnname) \ @@ -1925,7 +1961,7 @@ extern int *___errno (void) __attribute__((weak)); * alignment is greater than MAX_ALIGN (whatever that is). * Wrapper function that just calls memalign * - * Darwin. Does enforce size bing an integer multiple of + * Darwin. Does enforce size being an integer multiple of * alignment. * */ |
|
From: Paul F. <pa...@so...> - 2023-03-09 07:31:57
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=294894459a3c02505bbfa47a4f0326faad44632b commit 294894459a3c02505bbfa47a4f0326faad44632b Author: Paul Floyd <pj...@wa...> Date: Thu Mar 9 08:31:12 2023 +0100 regtest: try to fix bad merge of memalign_args expected on ppc64 Diff: --- memcheck/tests/memalign_args.stderr.exp-ppc64 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/memcheck/tests/memalign_args.stderr.exp-ppc64 b/memcheck/tests/memalign_args.stderr.exp-ppc64 index 2e289e86e7..bc3c0aba46 100644 --- a/memcheck/tests/memalign_args.stderr.exp-ppc64 +++ b/memcheck/tests/memalign_args.stderr.exp-ppc64 @@ -6,6 +6,10 @@ Conditional jump or move depends on uninitialised value(s) at 0x........: memalign (vg_replace_malloc.c:...) by 0x........: main (memalign_args.c:19) +Conditional jump or move depends on uninitialised value(s) + at 0x........: memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:19) + Conditional jump or move depends on uninitialised value(s) at 0x........: posix_memalign (vg_replace_malloc.c:...) by 0x........: main (memalign_args.c:23) @@ -28,7 +32,7 @@ Conditional jump or move depends on uninitialised value(s) Conditional jump or move depends on uninitialised value(s) at 0x........: memalign (vg_replace_malloc.c:...) - by 0x........: main (memalign_args.c:23) + by 0x........: main (memalign_args.c:26) Conditional jump or move depends on uninitialised value(s) at 0x........: memalign (vg_replace_malloc.c:...) |
|
From: Paul F. <pa...@so...> - 2023-03-09 07:04:58
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=e29bf11d87f3cd35ce49418b4e6c7d1e6d480a47 commit e29bf11d87f3cd35ce49418b4e6c7d1e6d480a47 Author: Paul Floyd <pj...@wa...> Date: Thu Mar 9 08:02:19 2023 +0100 regtest: update sized_aligned_new_delete_args expected Don't quite understand how I managed to generate the original expected. Diff: --- memcheck/tests/sized_aligned_new_delete_args.stderr.exp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/memcheck/tests/sized_aligned_new_delete_args.stderr.exp b/memcheck/tests/sized_aligned_new_delete_args.stderr.exp index 27047ef810..f79314a9f4 100644 --- a/memcheck/tests/sized_aligned_new_delete_args.stderr.exp +++ b/memcheck/tests/sized_aligned_new_delete_args.stderr.exp @@ -6,6 +6,10 @@ Conditional jump or move depends on uninitialised value(s) at 0x........: operator new(unsigned long, std::align_val_t) (vg_replace_malloc.c:...) by 0x........: main (sized_aligned_new_delete_args.cpp:16) +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_args.cpp:17) + Conditional jump or move depends on uninitialised value(s) at 0x........: operator new[](unsigned long, std::align_val_t) (vg_replace_malloc.c:...) by 0x........: main (sized_aligned_new_delete_args.cpp:19) |
|
From: Paul F. <pa...@so...> - 2023-03-08 22:12:32
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=d4affb0ab725a59da786fee4b918b338eec615fe commit d4affb0ab725a59da786fee4b918b338eec615fe Author: Paul Floyd <pj...@wa...> Date: Wed Mar 8 23:10:22 2023 +0100 Make operator new aligned more like the standalone versions If the alignment is not a power of two return nullptr for the nothrow overload and bomb for the throwing overload. Diff: --- .gitignore | 1 + coregrind/m_replacemalloc/vg_replace_malloc.c | 20 +++-- memcheck/tests/Makefile.am | 7 +- .../tests/sized_aligned_new_delete_misaligned.cpp | 86 ++++++++++++++++++++++ .../sized_aligned_new_delete_misaligned.stderr.exp | 10 +++ .../sized_aligned_new_delete_misaligned.vgtest | 3 + 6 files changed, 120 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index a4c7b510ba..d5e341063e 100644 --- a/.gitignore +++ b/.gitignore @@ -962,6 +962,7 @@ /memcheck/tests/sh-mem /memcheck/tests/sh-mem-random /memcheck/tests/sized_aligned_new_delete_args +/memcheck/tests/sized_aligned_new_delete_misaligned /memcheck/tests/sigaltstack /memcheck/tests/sigkill /memcheck/tests/signal2 diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 2b0879cd86..05bc9a4f61 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -294,13 +294,15 @@ extern int *___errno (void) __attribute__((weak)); TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \ MALLOC_TRACE(#fnname "(size %llu, al %llu)", (ULong)n, (ULong)alignment ); \ \ + if ((alignment == 0) \ + || ((alignment & (alignment - 1)) != 0)) { \ + return 0; \ + } \ + \ /* Round up to minimum alignment if necessary. */ \ if (alignment < VG_MIN_MALLOC_SZB) \ alignment = VG_MIN_MALLOC_SZB; \ \ - /* Round up to nearest power-of-two if necessary (like glibc). */ \ - while (0 != (alignment & (alignment - 1))) alignment++; \ - \ v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_##vg_replacement, n, alignment ); \ MALLOC_TRACE(" = %p\n", v ); \ if (!v) SET_ERRNO_ENOMEM; \ @@ -367,13 +369,19 @@ extern int *___errno (void) __attribute__((weak)); TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \ MALLOC_TRACE(#fnname "(size %llu, al %llu)", (ULong)n, (ULong)alignment ); \ \ + if ((alignment == 0) \ + || ((alignment & (alignment - 1)) != 0)) { \ + VALGRIND_PRINTF( \ + "new/new[] aligned failed and should throw an exception, but Valgrind\n"); \ + VALGRIND_PRINTF_BACKTRACE( \ + " cannot throw exceptions and so is aborting instead. Sorry.\n"); \ + my_exit(1); \ + } \ + \ /* Round up to minimum alignment if necessary. */ \ if (alignment < VG_MIN_MALLOC_SZB) \ alignment = VG_MIN_MALLOC_SZB; \ \ - /* Round up to nearest power-of-two if necessary (like glibc). */ \ - while (0 != (alignment & (alignment - 1))) alignment++; \ - \ v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_##vg_replacement, n, alignment ); \ MALLOC_TRACE(" = %p\n", v ); \ if (NULL == v) { \ diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index 98cecb9ca2..c9008ec5e7 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -142,6 +142,8 @@ EXTRA_DIST = \ sized_aligned_new_delete_args.stderr.exp \ sized_aligned_new_delete_args.vgtest \ sized_aligned_new_delete_args.stderr.exp_32 \ + sized_aligned_new_delete_misaligned.stderr.exp \ + sized_aligned_new_delete_misaligned.vgtest \ deep-backtrace.vgtest deep-backtrace.stderr.exp \ demangle.stderr.exp demangle.vgtest \ big_debuginfo_symbol.stderr.exp big_debuginfo_symbol.vgtest \ @@ -489,7 +491,8 @@ cdebug_zlib_gnu_CFLAGS = $(AM_CFLAGS) -g -gz=zlib-gnu @FLAG_W_NO_UNINITIALIZED@ endif if HAVE_ALIGNED_CXX_ALLOC -check_PROGRAMS += cxx17_aligned_new sized_aligned_new_delete_args +check_PROGRAMS += cxx17_aligned_new sized_aligned_new_delete_args \ + sized_aligned_new_delete_misaligned endif if HAVE_PTHREAD_BARRIER @@ -552,6 +555,8 @@ cxx17_aligned_new_SOURCES = cxx17_aligned_new.cpp cxx17_aligned_new_CXXFLAGS = -std=c++17 @FLAG_W_NO_MISMATCHED_NEW_DELETE@ sized_aligned_new_delete_args_SOURCES = sized_aligned_new_delete_args.cpp sized_aligned_new_delete_args_CXXFLAGS = ${AM_CXXFLAGS} -std=c++17 +sized_aligned_new_delete_misaligned_SOURCES = sized_aligned_new_delete_misaligned.cpp +sized_aligned_new_delete_misaligned_CXXFLAGS = ${AM_CXXFLAGS} -std=c++17 endif demangle_SOURCES = demangle.cpp diff --git a/memcheck/tests/sized_aligned_new_delete_misaligned.cpp b/memcheck/tests/sized_aligned_new_delete_misaligned.cpp new file mode 100644 index 0000000000..647fa5a850 --- /dev/null +++ b/memcheck/tests/sized_aligned_new_delete_misaligned.cpp @@ -0,0 +1,86 @@ +#include <cstdlib> +#include <new> +#include <iostream> +#include <cassert> +#include <cstdio> +#include <unistd.h> +#include <sys/types.h> +#include <sys/wait.h> +#include "valgrind.h" + +int main() { + std::align_val_t misalign(static_cast<std::align_val_t>(63U)); + std::align_val_t zeroalign(static_cast<std::align_val_t>(0U)); + std::align_val_t onealign(static_cast<std::align_val_t>(1U)); + std::align_val_t align(static_cast<std::align_val_t>(64U)); + size_t size(32); + std::nothrow_t tag; + void *mem = nullptr; + + // libc++ will allocate something for size zero + // but libstdc++ doesn't + mem = operator new(size, zeroalign, tag); + if (RUNNING_ON_VALGRIND) { + assert(!mem); + } + operator delete(mem, zeroalign, tag); + mem = nullptr; + + mem = operator new(size, onealign, tag); + assert(mem); + operator delete(mem, onealign, tag); + mem = nullptr; + + mem = operator new(size, align); + operator delete(mem, misalign); + mem = nullptr; + + mem = operator new[](size, align); + operator delete[](mem, misalign); + mem = nullptr; + + // doesn't matter that tag is uninit + // don't want to see an error + mem = operator new(size, misalign, tag); + operator delete(mem, misalign, tag); + assert(!mem); + + mem = operator new[](size, misalign, tag); + operator delete[](mem, misalign, tag); + assert(!mem); + + mem = operator new(size, align); + operator delete(mem, size, misalign); + mem = nullptr; + + mem = operator new[](size, align); + operator delete[](mem, size, misalign); + + // the last two throw exceptions in C++ + int pid; + int status; + pid = fork(); + if (pid == -1) { + perror("fork"); + exit(1); + } + if (pid == 0) { + // child + mem = operator new(size, misalign); + // should throw + assert(false); + } + waitpid(pid, &status, 0); + pid = fork(); + if (pid == -1) { + perror("fork"); + exit(1); + } + if (pid == 0) { + // child + mem = operator new[](size, misalign); + // should throw + assert(false); + } + waitpid(pid, &status, 0); +} diff --git a/memcheck/tests/sized_aligned_new_delete_misaligned.stderr.exp b/memcheck/tests/sized_aligned_new_delete_misaligned.stderr.exp new file mode 100644 index 0000000000..afbd817bad --- /dev/null +++ b/memcheck/tests/sized_aligned_new_delete_misaligned.stderr.exp @@ -0,0 +1,10 @@ +new/new[] aligned failed and should throw an exception, but Valgrind + cannot throw exceptions and so is aborting instead. Sorry. + ... + by 0x........: operator new(unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_misaligned.cpp:69) +new/new[] aligned failed and should throw an exception, but Valgrind + cannot throw exceptions and so is aborting instead. Sorry. + ... + by 0x........: operator new[](unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (sized_aligned_new_delete_misaligned.cpp:81) diff --git a/memcheck/tests/sized_aligned_new_delete_misaligned.vgtest b/memcheck/tests/sized_aligned_new_delete_misaligned.vgtest new file mode 100644 index 0000000000..fc7b6f4712 --- /dev/null +++ b/memcheck/tests/sized_aligned_new_delete_misaligned.vgtest @@ -0,0 +1,3 @@ +prog: sized_aligned_new_delete_misaligned +prereq: test -e ./sized_aligned_new_delete_misaligned +vgopts: -q |
|
From: Paul F. <pa...@so...> - 2023-03-08 20:34:58
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=bb5e8df5604214b690ab39445014bfb284450b00 commit bb5e8df5604214b690ab39445014bfb284450b00 Author: Paul Floyd <pj...@wa...> Date: Wed Mar 8 21:33:36 2023 +0100 regtest: add an arm expected for memalign_args Diff: --- memcheck/tests/Makefile.am | 1 + memcheck/tests/memalign_args.stderr.exp-arm | 40 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index 72d56cfa48..98cecb9ca2 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -223,6 +223,7 @@ EXTRA_DIST = \ memalign_args.vgtest memalign_args.stderr.exp \ memalign_args.stderr.exp-glibc \ memalign_args.stderr.exp-ppc64 \ + memalign_args.stderr.exp-arm \ memcmptest.stderr.exp memcmptest.stderr.exp2 \ memcmptest.stdout.exp memcmptest.vgtest \ memmem.stderr.exp memmem.vgtest \ diff --git a/memcheck/tests/memalign_args.stderr.exp-arm b/memcheck/tests/memalign_args.stderr.exp-arm new file mode 100644 index 0000000000..093accfb7e --- /dev/null +++ b/memcheck/tests/memalign_args.stderr.exp-arm @@ -0,0 +1,40 @@ +Conditional jump or move depends on uninitialised value(s) + at 0x........: memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:19) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:19) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:19) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: posix_memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:23) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: posix_memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:23) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: posix_memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:23) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:26) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:26) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:26) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: valloc (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:29) + |
|
From: Mark W. <ma...@kl...> - 2023-03-08 11:04:52
|
Sourceware infrastructure community updates for Q1 2023. = New cgit setup gitweb has been working out pretty nicely for many years, but cgit is cgit is nicer looking, has easier to understand URLs and is much faster. The first experimental setup can be found here: https://cygwin.com/cgit/ https://gcc.gnu.org/cgit/ https://sourceware.org/cgit/ Thanks to Jon Turney for the cygwin work. If this works out, we would like to deploy a script written by Arsen Arsenović to switch the main /git/ to cgit while keeping all old gitweb URLs working. See https://sourceware.org/bugzilla/show_bug.cgi?id=29769 = New sparc builder for builder.sourceware.org Thanks to the Gentoo Foundation and OSUOSL [*] there is now a large (and small) gentoo-sparc worker: https://builder.sourceware.org/buildbot/#/workers/35 https://builder.sourceware.org/buildbot/#/workers/36 Please contact the buildbot mailinglis if you want to do specific builds on it: https://sourceware.org/mailman/listinfo/buildbot = AI comes to the bunsen test results It isn't a large language model chatbot, but probably more useful. https://builder.sourceware.org/testruns/ will now predict what it believes the the dejagnu test results should be. It will give a score for what it expected a result to be. e.g for a new FAIL it could say: mispredicted PASS 81% which means in 81% of similar test runs that test PASSed. So you can concentrate on those FAILing tests that have a high PASSing score. For more info see: https://inbox.sourceware.org/buildbot/202...@re.../ = openssh update produces misleading invalid key length warning Connecting to sourceware through ssh with a newer openssh or crypto policy might produce a misleading warning about the key length being too short: Bad server host key: Invalid key length Please don't try to replace your ssh key, there is nothing wrong with it. The issue is that you might have an old server key in your ~/.ssh/known_hosts file. Simply remove it and reconnect to get the new server key: ssh-keygen -R sourceware.org ssh-keygen -R cygwin.com ssh-keygen -R gcc.gnu.org See also https://bugzilla.redhat.com/show_bug.cgi?id=2164016 = inbox.sourceware.org and '/' in Message-ID Those using public-inbox might have noticed that when a Message-ID contains a slash character '/' it is not always correctly encoded or decoded as %2F in the inbox.sourceware.org path URLs. If you are using a newer mutt as email client then you might want to make sure that your Message-ID doesn't contain any characters that might need URL encoding. For mutt 2.2 you might want to set the following in your ~/.muttrc to produce a uuid-like Message-ID as other email clients do: set message_id_format="<%x%x%x%x-%x%x-%x%x-%x%x-%x%x%x%x%x%x@%f>" For older mutt, and some more background, see: https://people.kernel.org/monsieuricon/fix-your-mutt = Happy hacking And as always please feel free join the overseers mailinglist https://sourceware.org/mailman/listinfo/overseers file infrastructure issues in bugzilla https://sourceware.org/bugzilla/describecomponents.cgi?product=sourceware or join us in #overseers on irc.libera.chat [*] But specifically Sam James. We should also thank the following other individuals and organisations for maintaining and/or providing hardware for builder.sourceware.org Brno University, Dan Horák, Marist University, Thomas Fitzsimmons, Mark Wielaard, Frank Eigler, IBM, Carl Love, The Works on Arm initiative, Christophe Lyon, and Red Hat |