#1923 closed defect (duplicate)

Potential Memory Leak in directory 'src/core'. file 'ngx_inet.c'

Reported by: wp02855@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.15.x
Keywords: 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: 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_inet.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:

--- ngx_inet.c.orig 2019-12-12 12:03:25.414107400 -0800
+++ ngx_inet.c 2019-12-12 12:13:22.386814300 -0800
@@ -751,6 +751,7 @@

saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un));
if (saun == NULL) {

+ ngx_pfree(u->addrs); /* release memory from u->addrs */

return NGX_ERROR;

}


@@ -913,6 +914,7 @@

sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));
if (sin == NULL) {

+ ngx_pfree(u->addrs); /* release memory from u->addrs */

return NGX_ERROR;

}


@@ -1070,6 +1072,7 @@

sin6 = ngx_pcalloc(pool, sizeof(struct sockaddr_in6));
if (sin6 == NULL) {

+ ngx_pfree(u->addrs); /* release memory from u->addrs */

return NGX_ERROR;

}


@@ -1296,6 +1299,7 @@

sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));
if (sin == NULL) {

+ ngx_pfree(u->addrs); /* release memory allocated to u->addrs */

return NGX_ERROR;

}


@@ -1310,6 +1314,8 @@

p = ngx_pnalloc(pool, len);
if (p == NULL) {

+ ngx_pfree(sin); /* release memory allocated to sin */
+ ngx_pfree(u->addrs); /* release memory allocated to u->addrs */

return NGX_ERROR;

}


@@ -1331,6 +1337,7 @@

sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));
if (sin == NULL) {

+ ngx_pfree(u->addrs); /* release memory assigned to u->addrs */

return NGX_ERROR;

}


@@ -1345,6 +1352,8 @@

p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1);
if (p == NULL) {

+ ngx_pfree(sin); /* release memory assigned to sin */
+ ngx_pfree(u->addrs); /* release memory assigned to u->addrs */

return NGX_ERROR;

}

Attachments (1)

ngx_inet.c.patch (1.7 KB ) - added by wp02855@… 11 months ago.
patch file for bug reported in ticket 1923

Download all attachments as: .zip

Change History (2)

by wp02855@…, 11 months ago

Attachment: ngx_inet.c.patch added

patch file for bug reported in ticket 1923

comment:1 by Maxim Dounin, 11 months ago

Resolution: duplicate
Status: newclosed

Duplicate of #1914.

Note: See TracTickets for help on using tickets.