<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">This is getting quite tiresome. You are both stuck in your point of view and refusing to hear what the other one is saying.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Maxim - you keep repeating "
l->alloc is not used after free(). " Clearly, that is not true if setting it to NULL prevents the segfault. What is true is that NGINX core code does not use it. As a defensive coding technique, I agree with zjd that setting the pointer you just freed to NULL to indicate to any other code that is checking it is the proper action. The only other thing that zjd can do is to set the pointer to NULL in their own code after calling the reset function if you are adamant that such defensive measures cannot be put into the NGINX core code. Any future programmers that write modules like zjd has done that test a pointer for being NULL and use it if it has a non-NULL value, will trip over the same problem, and you can have this argument all over again.<br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">~ Frank Swasey, lurker<br> </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 29, 2022 at 3:53 PM Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</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">Hello!<br>
<br>
On Thu, Sep 29, 2022 at 04:30:45PM +0800, zjd wrote:<br>
<br>
> Actually, I'm not sure where is coredump; So I think <br>
> l->alloc=NULL after free(l-alloc) is reasonable, because <br>
> l->alloc's address can be reused in the pool. Of course, <br>
> memzero after get mem from the pool can be solved about this <br>
> question.But for example, ngx_array_push maybe reuse l->alloc's <br>
> address, and ngx_array_push is not memzero from the start of <br>
> get memory.<br>
> So I think l->alloc=NULL after free(l-alloc) is necessary. <br>
> Thanks for discussing this with me<br>
<br>
As previously explained, l->alloc is not used after free(). <br>
Clearing unused memory without reasons is certainly not necessary, <br>
much like clearing allocated memory. While it might be helpful to <br>
mitigate various bugs, a better approach would be to find and fix <br>
bugs.<br>
<br>
To find and fix bugs a better approach is usually to set the <br>
unused memory to a pattern which is more likely to cause segfault <br>
if used, such as memset(0x5A). In nginx, various mechanisms to <br>
facilitate memory debugging are available with NGX_DEBUG_MALLOC <br>
and NGX_DEBUG_PALLOC defines, see code for details. Using system <br>
allocator options, Address Sanitizer, and tools like Valgrind also <br>
might be helpful.<br>
<br>
-- <br>
Maxim Dounin<br>
<a href="http://mdounin.ru/" rel="noreferrer" target="_blank">http://mdounin.ru/</a><br>
_______________________________________________<br>
nginx mailing list -- <a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
To unsubscribe send an email to <a href="mailto:nginx-leave@nginx.org" target="_blank">nginx-leave@nginx.org</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">I am not young enough to know everything. - Oscar Wilde (1854-1900)</div>