Thread (2 messages) 2 messages, 2 authors, 2025-02-02

Re: [PATCH] man/man2/clone.2: Use munmap() to free child stack

From: Alejandro Colomar <alx@kernel.org>
Date: 2025-02-02 16:56:14

Hi Chen,

On Tue, Jan 21, 2025 at 11:13:51AM +0800, Chen Linxuan wrote:
quoted hunk ↗ jump to hunk
While reading the help manual for clone.2, I notice that the parent
process in the example code does not release the stack of the child
process.

This is not a problem for the example program, but it is somewhat
misleading.

Signed-off-by: Chen Linxuan <redacted>
---
 man/man2/clone.2 | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/man/man2/clone.2 b/man/man2/clone.2
index 3ffe8e7b8..5e6b2ef1f 100644
--- a/man/man2/clone.2
+++ b/man/man2/clone.2
@@ -1910,6 +1910,8 @@ main(int argc, char *argv[])
        child commences execution in childFunc(). */
 \&
     pid = clone(childFunc, stackTop, CLONE_NEWUTS | SIGCHLD, argv[1]);
+    if (munmap(stack, STACK_SIZE))
+        err(EXIT_FAILURE, "munmap");
     if (pid == \-1)
Would you mind clarifying why this munmap(2) call goes before the error
handling of clone(2)?  I'm not very familiar with clone(2).


Have a lovely day!
Alex
         err(EXIT_FAILURE, "clone");
     printf("clone() returned %jd\[rs]n", (intmax_t) pid);
-- 
2.43.0
-- 
<https://www.alejandro-colomar.es/>

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help