https://bugs.kde.org/show_bug.cgi?id=182042

Paul Floyd <pjfl...@wanadoo.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REPORTED                    |RESOLVED
         Resolution|---                         |NOT A BUG
                 CC|                            |pjfl...@wanadoo.fr

--- Comment #5 from Paul Floyd <pjfl...@wanadoo.fr> ---
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)

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to