Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#1914 closed defect (invalid)

Memory Leak in directory 'src/core', file 'ngx_buf.c'

Reported by: wp02855@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.17.x
Keywords: potential memory leak(s) Cc:
uname -a: bill@foobar 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 PST 2019 x86_64 GNU/Linux
nginx -V: version 1.15.0 (using static analysis of source code)

Description

In reviewing source code in nginx-1.15.0, it would appear that there are some memory leaks in file 'ngx_buf.c' which when functions in this file are called, the memory allocations are not released, leading to over-utilization of memory over time, the patch file is below:

@@ -21,6 +21,7 @@

b->start = ngx_palloc(pool, size);
if (b->start == NULL) {

+ ngx_free(b); /* release previous memory allocation before going home */

return NULL;

}

@@ -84,7 +85,8 @@

b = ngx_calloc_buf(pool);
if (b == NULL) {

  • return NULL;

+ ngx_free(p); /* release previous memory allocation and go home */
+ return NULL; /* how do we handle previous allocations of ngx_calloc_buf()? */

}

/*

Attachments (1)

ngx_buf.c.patch (600 bytes ) - added by wp02855@… 3 months ago.
patch file for bug reported in ticket 1914

Download all attachments as: .zip

Change History (7)

by wp02855@…, 3 months ago

Attachment: ngx_buf.c.patch added

patch file for bug reported in ticket 1914

comment:1 by Shmulik Biran, 3 months ago

You seem to be missing the concepts of nginx memory management.
None of the tickets you just opened looks like actual leaks.
Please refer to:
http://nginx.org/en/docs/dev/development_guide.html#pool

comment:2 by Maxim Dounin, 3 months ago

Resolution: invalid
Status: newclosed

The code in question uses allocations from a memory pool, and all allocations are freed when the pool is destroyed. There is no need to do any explicit free operations. Further, the patch tries to call ngx_free(), which is completely wrong, as this call is not memory pool aware.

Hope this helps. If you have further questions on nginx code, consider using mailing lists instead.

comment:3 by Maxim Dounin, 3 months ago

See also #1915, #1916.

comment:4 by Maxim Dounin, 3 months ago

See also #1917.

comment:5 by Maxim Dounin, 3 months ago

See also #1918, #1919, #1920.

comment:6 by Maxim Dounin, 3 months ago

See also #1921, #1922, #1923.

Note: See TracTickets for help on using tickets.