Opened 6 years ago
Closed 6 years ago
#1721 closed enhancement (fixed)
One line redundant code in ngx_slab_free_locked
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | nginx-core | Version: | 1.15.x |
Keywords: | ngx_slab_free | Cc: | |
uname -a: | |||
nginx -V: | nginx version: nginx/1.15.8 |
Description
Hi, When I read the source code of Nginx, I notice there is one line redundant code in ngx_slab_free_locked.
n = ((u_char *) p - pool->start) >> ngx_pagesize_shift;
In the beginning of this function, 'n' has been calculated, but in the case NGX_SLAB_PAGE, it is calculated again.
Please see the patch, thanks.
Attachments (1)
Note:
See TracTickets
for help on using tickets.
The
n
variable is used in the following&pool->pages[n]
reference, and using generic multi-purpose variables in the parts of code distant from the code where it is calculated is generally a bad idea. Even if in a particular moment the variable stays intact, it can be overwritten at some point later, breaking things.On the other hand, calculating
&pool->pages[n]
looks unneeded too, as we already havepage
pointer. It should be fine to simply usepage
instead of re-calculating it. Please test if the following patch works for you: