* [PATCH] trace-cmd test: Quiet valgrind from reporting forked children
@ 2023-06-07 17:52 Steven Rostedt
0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2023-06-07 17:52 UTC (permalink / raw)
To: Linux Trace Devel; +Cc: Tzvetomir Stoyanov
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
valgrind triggers its reports when the application exits. If the application
does a fork() and the child exits, it will still trigger a report saying that
the memory that was currently allocated by the parent has leaked.
To prevent this, call execl() on a shell script that will simply exit with the
proper error code. This will keep valgrind from producing a report on the
child for the memory that is still allocated by the parent.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
Changes since v1:
utest/tracecmd-utest.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/utest/tracecmd-utest.c b/utest/tracecmd-utest.c
index 34fed1e1..11f7f460 100644
--- a/utest/tracecmd-utest.c
+++ b/utest/tracecmd-utest.c
@@ -131,6 +131,7 @@ static int pipe_it(int *ofd, int *efd, int (*func)(void *),
goto fail;
if (!pid) {
+ char shret[32];
close(obrass[0]);
close(STDOUT_FILENO);
@@ -143,6 +144,22 @@ static int pipe_it(int *ofd, int *efd, int (*func)(void *),
exit(-1);
ret = func(data);
+
+ /*
+ * valgrind triggers its reports when the application
+ * exits. If the application does a fork() and the child
+ * exits, it will still trigger the valgrind report for
+ * all the allocations that were not freed by the parent.
+ *
+ * To prevent valgrind from triggering, do an execl() on
+ * a basic shell that will simply exit with the return value.
+ * This will quiet valgrind from reporting memory that has
+ * been allocated by the parent up to here.
+ */
+ snprintf(shret, 32, "exit %d", ret);
+ execl("/usr/bin/sh", "/usr/bin/sh", "-c", shret, NULL);
+
+ /* If the above execl() fails, simply do an exit */
exit(ret);
}
--
2.35.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-06-07 17:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-07 17:52 [PATCH] trace-cmd test: Quiet valgrind from reporting forked children Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).