Opened 5 years ago
Closed 5 years ago
#1923 closed defect (duplicate)
Potential Memory Leak in directory 'src/core'. file 'ngx_inet.c'
Reported by: | 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;
}
patch file for bug reported in ticket 1923