<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 13, 2019 at 6:16 PM Jan Stancek <<a href="mailto:jstancek@redhat.com" target="_blank">jstancek@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
----- Original Message -----<br>
> On Thu, Jun 13, 2019 at 3:25 PM Jan Stancek <<a href="mailto:jstancek@redhat.com" target="_blank">jstancek@redhat.com</a>> wrote:<br>
> <br>
> > Test crashes (SIGBUS) when using child stack have been observed for<br>
> > ioctl_ns01. This is because stack isn't aligned. Use ltp_alloc_stack()<br>
> > for stack allocation.<br>
> ><br>
> > Add SIGCHLD to clone flags, so that LTP library can reap all children<br>
> > and check their return code. Also check ltp_clone() return value.<br>
> ><br>
> > Suppress warning for unused *arg in child().<br>
> ><br>
> > Signed-off-by: Jan Stancek <<a href="mailto:jstancek@redhat.com" target="_blank">jstancek@redhat.com</a>><br>
> > ---<br>
> > testcases/kernel/syscalls/ioctl/ioctl_ns01.c | 13 +++++++++----<br>
> > testcases/kernel/syscalls/ioctl/ioctl_ns05.c | 12 +++++++++---<br>
> > testcases/kernel/syscalls/ioctl/ioctl_ns06.c | 15 +++++++++++----<br>
> > 3 files changed, 29 insertions(+), 11 deletions(-)<br>
> ><br>
> > diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns01.c<br>
> > b/testcases/kernel/syscalls/ioctl/ioctl_ns01.c<br>
> > index dfde4da6c5d6..d241a5d0fa53 100644<br>
> > --- a/testcases/kernel/syscalls/ioctl/ioctl_ns01.c<br>
> > +++ b/testcases/kernel/syscalls/ioctl/ioctl_ns01.c<br>
> > @@ -23,7 +23,7 @@<br>
> ><br>
> > #define STACK_SIZE (1024 * 1024)<br>
> ><br>
> > -static char child_stack[STACK_SIZE];<br>
> > +static char *child_stack;<br>
> ><br>
> > static void setup(void)<br>
> > {<br>
> > @@ -31,6 +31,10 @@ static void setup(void)<br>
> ><br>
> > if (exists < 0)<br>
> > tst_res(TCONF, "namespace not available");<br>
> > +<br>
> > + child_stack = ltp_alloc_stack(STACK_SIZE);<br>
> ><br>
> <br>
> As you commented that "User is responsible for freeing allocated memory",<br>
> but you forget to do that in each of these test cases :).<br>
<br>
I omitted it on purpose. OS will clean it up on exit, since it's called<br>
only in setup() it's not going to keep leaking more memory.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Okay. I believe that, but it is not a recommended coding habit which I had been told ;-).</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> <br>
> We need free(child_stack) in the cleanup function.<br>
<br>
Can you elaborate?<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">Nothing else. It is just a supplementary as above comment. If we do memory release, then add:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">static void cleanup(viod)</div><div class="gmail_default" style="font-size:small">{</div><div class="gmail_default" style="font-size:small"> if (child_stack)</div><div class="gmail_default" style="font-size:small"> free(child_stack);</div><div class="gmail_default" style="font-size:small">}</div></div><div><br></div>-- <br><div dir="ltr" class="m_6996575859477631196gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>