Re: [patch] on_exit.3: Add example code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 14 Jun 2019 at 15:22, Michael Kerrisk (man-pages)
<mtk.manpages@xxxxxxxxx> wrote:
> I'm quite confused by your terminology and your example.
>
> Above you've talked about heap variables not being in scope for
> the exit handler established by on_exit(). And in your initial mail,
> you said "In short only variables allocated from stack make is
> sense when calling on_exit()."
>
> But your code examples above demonstrate exactly the opposite, as
> far as I can see. 'broken.c' use *a stack variable from main()*
> as the argument for the exit handler, and that does not work.
> 'works.c' used a *heap variable* as as the argument for the
> exit handler, and that *does* work, as your example demonstrates.
>
> The fact that stack variable from main() are not in scope for
> on_exit() after a return from main() is pretty much expected,
> since main() has gone out of scope already.
>
> However, it's not clear to me that heap variables are out of
> scope for the exit handler. Your example doesn't demonstrate
> that. And, offhand, I can see no reason why heap variables
> would have to be out of scope. And my own experiments (see test
> program below) seem to indicate that heap variables are in
> scope. My only doubt is what the standards have to say on the
> issue, but I did not so far spot any relevant text.
>
> Your thoughts on the above?

Hi Michael,

Oh sorry, I mixed up terminology.  I should have said 'allocated memory' and
'local variable' in function that calls on_exit() instead of heap and stack.
Trouble of non-native english and words that at least I associate nothing
but large quantities and piles os stuff without much distinction.

Anyway, the code example in my previous email demonstrated how one might
think local variables could be used (incorrectly).  In hindsight use of
local variables is wrong, and that is the point.  Allocated memory can be
passed to on_exit() and nothing else makes sense.  While one could pass
global variable to on_exit() in that case more portable atexit() is better
option.

Recommendation in 'confirming to' section to avoid this function in portable
applications is good.  Whether telling on_exit() is mostly useful as a hook
to unallocate memory just before exit might be worth while.

-- 
Sami Kerola
http://www.iki.fi/kerolasa/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux