fix accidental corrdump
Maxim Dounin
mdounin at mdounin.ru
Thu Sep 29 19:52:19 UTC 2022
Hello!
On Thu, Sep 29, 2022 at 04:30:45PM +0800, zjd wrote:
> Actually, I'm not sure where is coredump; So I think
> l->alloc=NULL after free(l-alloc) is reasonable, because
> l->alloc's address can be reused in the pool. Of course,
> memzero after get mem from the pool can be solved about this
> question.But for example, ngx_array_push maybe reuse l->alloc's
> address, and ngx_array_push is not memzero from the start of
> get memory.
> So I think l->alloc=NULL after free(l-alloc) is necessary.
> Thanks for discussing this with me
As previously explained, l->alloc is not used after free().
Clearing unused memory without reasons is certainly not necessary,
much like clearing allocated memory. While it might be helpful to
mitigate various bugs, a better approach would be to find and fix
bugs.
To find and fix bugs a better approach is usually to set the
unused memory to a pattern which is more likely to cause segfault
if used, such as memset(0x5A). In nginx, various mechanisms to
facilitate memory debugging are available with NGX_DEBUG_MALLOC
and NGX_DEBUG_PALLOC defines, see code for details. Using system
allocator options, Address Sanitizer, and tools like Valgrind also
might be helpful.
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx
mailing list