| Summary: | valgrind silently ignores VALGRIND_OPTS env var if environment is not propagated to the process | ||
|---|---|---|---|
| Product: | [Developer tools] valgrind | Reporter: | Nuno Lopes <nunoplopes> |
| Component: | general | Assignee: | Julian Seward <jseward> |
| Status: | RESOLVED NOT A BUG | ||
| Severity: | normal | CC: | greened, njn, pjfloyd |
| Priority: | NOR | ||
| Version First Reported In: | unspecified | ||
| Target Milestone: | wanted3.6.0 | ||
| Platform: | Compiled Sources | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
| Attachments: |
test case
output of the tests |
||
|
Description
Nuno Lopes
2009-01-27 00:05:54 UTC
Created attachment 30649 [details]
test case
compile with gcc -o vg-test vg-test.c
Created attachment 30650 [details]
output of the tests
output of the tests with and without using the VALGRIND_OPTS env var. note that I expected both outputs to be similar.
I also see this problem in 3.5.0 (In reply to comment #3) > I also see this problem in 3.5.0 Ah, my mistake. It appears to work in 3.5.0. I don't see how Valgrind can miraculously recover envp from the child when you pass it a null environment.
You need to progagate the parent envp to the child like this:
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv, char **envp)
{
char *args[] = {"vg-test", "child", NULL};
// main process
if (argc == 1) {
execve("./vg-test", args, envp);
} else {
(void)malloc(3); // leak in the child
}
return 0;
}
This gives me
valgrind --trace-children=yes --leak-check=full ./vg-test
==36462== Memcheck, a memory error detector
==36462== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==36462== Using Valgrind-3.21.0.GIT and LibVEX; rerun with -h for copyright info
==36462== Command: ./vg-test
==36462==
==36462== Memcheck, a memory error detector
==36462== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==36462== Using Valgrind-3.21.0.GIT and LibVEX; rerun with -h for copyright info
==36462== Command: ./vg-test child
==36462==
==36462==
==36462== HEAP SUMMARY:
==36462== in use at exit: 3 bytes in 1 blocks
==36462== total heap usage: 1 allocs, 0 frees, 3 bytes allocated
==36462==
==36462== 3 bytes in 1 blocks are definitely lost in loss record 1 of 1
==36462== at 0x484CBC4: malloc (in /usr/local/libexec/valgrind/vgpreload_memcheck-amd64-freebsd.so)
==36462== by 0x20196D: main (vg-test.c:12)
==36462==
==36462== LEAK SUMMARY:
==36462== definitely lost: 3 bytes in 1 blocks
==36462== indirectly lost: 0 bytes in 0 blocks
==36462== possibly lost: 0 bytes in 0 blocks
==36462== still reachable: 0 bytes in 0 blocks
==36462== suppressed: 0 bytes in 0 blocks
==36462==
==36462== For lists of detected and suppressed errors, rerun with: -s
==36462== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
|