[CC += linux-man@] Hi Pali, On Tue, Nov 19, 2024 at 12:55:02PM +0100, Pali Rohár wrote: > Hello Alex, > > In alloca() manpage https://man7.org/linux/man-pages/man3/alloca.3.html > is following information in NOTES section: > > Because the space allocated by alloca() is allocated within the > stack frame, that space is automatically freed if the function > return is jumped over by a call to longjmp(3) or siglongjmp(3). > > The space allocated by alloca() is not automatically deallocated > if the pointer that refers to it simply goes out of scope. > > One developer contacted me about this section as he was saying to me > that he alloca() function (thanks to above information) does not release > the allocated space just by returning from the function. And it is > required to do long-jump to release memory allocated by the alloca(). > Developer was referring to the second sentence (something like end of > the function is also end of the scope, and second sentence says that it > is NOT automatically deallocated) and then to the first sentence that > longjmp() is needed to call. > > I think that this interpretation is just a nonsense as alloca() function > always allocates on the stack and all stack usage is released at the end > of the function. > > But... I was reading those two sentences isolated and I must admit that > as they are quite confusing. And somebody who first see alloca() > function (and has no idea how it works), can be confused. Agree. > What about improving those two sentences, to prevent misunderstanding? > > For example: > > The space allocated by alloca() is not automatically deallocated > if the pointer that refers to it simply goes out of scope (unless > end of the scope is also end of the function). I've applied a slightly different wording, but yeah, LGTM. <https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib> commit a6e8435b161a513576ce39f524f4fbd3eb621fe7 (HEAD -> contrib, alx/contrib) Author: Alejandro Colomar <alx@xxxxxxxxxx> Date: Tue Nov 19 13:17:27 2024 +0100 alloca.3: Clarify that alloca(3)ted space is deallocated when the function returns Reported-by: Pali Rohár <pali@xxxxxxxxxx> Signed-off-by: Alejandro Colomar <alx@xxxxxxxxxx> diff --git a/man/man3/alloca.3 b/man/man3/alloca.3 index 0d079ac1d..0baf8f1ce 100644 --- a/man/man3/alloca.3 +++ b/man/man3/alloca.3 @@ -87,7 +87,8 @@ .SH NOTES is .I not automatically deallocated if the pointer that refers to it -simply goes out of scope. +simply goes out of scope; +it is automatically deallocated when the function returns. .P Do not attempt to .BR free (3) Thanks for the report! Have a lovely day! Alex P.S.: Please use <alx@xxxxxxxxxx>. I'm deprecating my google accounts. P.S.2: Please remember to CC linux-man@. > > > Pali -- <https://www.alejandro-colomar.es/>
Attachment:
signature.asc
Description: PGP signature