Skip to content

Commit 6b01840

Browse files
committed
change: disabled the mmap(sbrk(0)) memory trick since glibc leaks memory when it is forced to use mmap to fulfill malloc().
1 parent 743a10a commit 6b01840

File tree

4 files changed

+25
-91
lines changed

4 files changed

+25
-91
lines changed

config

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -472,33 +472,6 @@ ngx_feature_test='setsockopt(1, SOL_SOCKET, SO_PASSCRED, NULL, 0);'
472472

473473
. auto/feature
474474

475-
ngx_feature="mmap(sbrk(0))"
476-
ngx_feature_libs=
477-
ngx_feature_name="NGX_HTTP_LUA_HAVE_MMAP_SBRK"
478-
ngx_feature_run=yes
479-
ngx_feature_incs="#include <unistd.h>
480-
#include <stdlib.h>
481-
#include <stdint.h>
482-
#include <sys/mman.h>
483-
#define align_ptr(p, a) \
484-
(u_char *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1))
485-
"
486-
ngx_feature_test="
487-
#if defined(__x86_64__)
488-
exit(mmap(align_ptr(sbrk(0), getpagesize()), 1, PROT_READ,
489-
MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1, 0) < (void *) 0x40000000LL
490-
? 0 : 1);
491-
#else
492-
exit(1);
493-
#endif
494-
"
495-
SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
496-
CC_TEST_FLAGS="-Werror -Wall $CC_TEST_FLAGS"
497-
498-
. auto/feature
499-
500-
CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
501-
502475
ngx_feature="__attribute__(constructor)"
503476
ngx_feature_libs=
504477
ngx_feature_name="NGX_HTTP_LUA_HAVE_CONSTRUCTOR"

src/ngx_http_lua_module.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ static char *ngx_http_lua_lowat_check(ngx_conf_t *cf, void *post, void *data);
4545
static ngx_int_t ngx_http_lua_set_ssl(ngx_conf_t *cf,
4646
ngx_http_lua_loc_conf_t *llcf);
4747
#endif
48-
#if (NGX_HTTP_LUA_HAVE_MMAP_SBRK) && (NGX_LINUX)
49-
/* we cannot use "static" for this function since it may lead to compiler
50-
* warnings */
51-
void ngx_http_lua_limit_data_segment(void);
52-
# if !(NGX_HTTP_LUA_HAVE_CONSTRUCTOR)
53-
static ngx_int_t ngx_http_lua_pre_config(ngx_conf_t *cf);
54-
# endif
55-
#endif
5648
static char *ngx_http_lua_malloc_trim(ngx_conf_t *cf, ngx_command_t *cmd,
5749
void *conf);
5850

@@ -592,13 +584,7 @@ static ngx_command_t ngx_http_lua_cmds[] = {
592584

593585

594586
ngx_http_module_t ngx_http_lua_module_ctx = {
595-
#if (NGX_HTTP_LUA_HAVE_MMAP_SBRK) \
596-
&& (NGX_LINUX) \
597-
&& !(NGX_HTTP_LUA_HAVE_CONSTRUCTOR)
598-
ngx_http_lua_pre_config, /* preconfiguration */
599-
#else
600587
NULL, /* preconfiguration */
601-
#endif
602588
ngx_http_lua_init, /* postconfiguration */
603589

604590
ngx_http_lua_create_main_conf, /* create main configuration */
@@ -1267,37 +1253,6 @@ ngx_http_lua_set_ssl(ngx_conf_t *cf, ngx_http_lua_loc_conf_t *llcf)
12671253
#endif /* NGX_HTTP_SSL */
12681254

12691255

1270-
#if (NGX_HTTP_LUA_HAVE_MMAP_SBRK) \
1271-
&& (NGX_LINUX) \
1272-
&& !(NGX_HTTP_LUA_HAVE_CONSTRUCTOR)
1273-
static ngx_int_t
1274-
ngx_http_lua_pre_config(ngx_conf_t *cf)
1275-
{
1276-
ngx_http_lua_limit_data_segment();
1277-
return NGX_OK;
1278-
}
1279-
#endif
1280-
1281-
1282-
/*
1283-
* we simply assume that LuaJIT is used. it does little harm when the
1284-
* standard Lua 5.1 interpreter is used instead.
1285-
*/
1286-
#if (NGX_HTTP_LUA_HAVE_MMAP_SBRK) && (NGX_LINUX)
1287-
# if (NGX_HTTP_LUA_HAVE_CONSTRUCTOR)
1288-
__attribute__((constructor))
1289-
# endif
1290-
void
1291-
ngx_http_lua_limit_data_segment(void)
1292-
{
1293-
if (sbrk(0) < (void *) 0x40000000LL) {
1294-
mmap(ngx_align_ptr(sbrk(0), getpagesize()), 1, PROT_READ,
1295-
MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1, 0);
1296-
}
1297-
}
1298-
#endif
1299-
1300-
13011256
static char *
13021257
ngx_http_lua_malloc_trim(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
13031258
{

t/141-luajit.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# vim:set ft= ts=4 sw=4 et fdm=marker:
22

3-
use Test::Nginx::Socket::Lua;
3+
use Test::Nginx::Socket::Lua
4+
skip_all => 'no mmap(sbrk(0)) trick since glibc leaks memory in this case';
45

56
#worker_connections(1014);
67
#master_on();

t/146-malloc-trim.t

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ ok
4343
ok
4444
ok
4545
--- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
46-
--- grep_error_log_out
47-
malloc_trim(1) returned 0
46+
--- grep_error_log_out eval
47+
qr/\Amalloc_trim\(1\) returned [01]
48+
\z/
4849
--- wait: 0.2
4950
--- no_error_log
5051
[error]
@@ -76,13 +77,14 @@ ok
7677
ok
7778
ok
7879
--- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
79-
--- grep_error_log_out
80-
malloc_trim(1) returned 0
81-
malloc_trim(1) returned 0
82-
malloc_trim(1) returned 0
83-
malloc_trim(1) returned 0
84-
malloc_trim(1) returned 0
85-
malloc_trim(1) returned 0
80+
--- grep_error_log_out eval
81+
qr/\Amalloc_trim\(1\) returned [01]
82+
malloc_trim\(1\) returned [01]
83+
malloc_trim\(1\) returned [01]
84+
malloc_trim\(1\) returned [01]
85+
malloc_trim\(1\) returned [01]
86+
malloc_trim\(1\) returned [01]
87+
\z/
8688
--- wait: 0.2
8789
--- no_error_log
8890
[error]
@@ -114,10 +116,11 @@ ok
114116
ok
115117
ok
116118
--- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
117-
--- grep_error_log_out
118-
malloc_trim(1) returned 0
119-
malloc_trim(1) returned 0
120-
malloc_trim(1) returned 0
119+
--- grep_error_log_out eval
120+
qr/\Amalloc_trim\(1\) returned [01]
121+
malloc_trim\(1\) returned [01]
122+
malloc_trim\(1\) returned [01]
123+
\z/
121124
--- wait: 0.2
122125
--- no_error_log
123126
[error]
@@ -149,9 +152,10 @@ ok
149152
ok
150153
ok
151154
--- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
152-
--- grep_error_log_out
153-
malloc_trim(1) returned 0
154-
malloc_trim(1) returned 0
155+
--- grep_error_log_out eval
156+
qr/\Amalloc_trim\(1\) returned [01]
157+
malloc_trim\(1\) returned [01]
158+
\z/
155159
--- wait: 0.2
156160
--- no_error_log
157161
[error]
@@ -330,8 +334,9 @@ ok
330334
ok
331335
ok
332336
--- grep_error_log eval: qr/malloc_trim\(\d+\) returned \d+/
333-
--- grep_error_log_out
334-
malloc_trim(1) returned 0
337+
--- grep_error_log_out eval
338+
qr/\Amalloc_trim\(1\) returned [01]
339+
\z/
335340
--- wait: 0.2
336341
--- no_error_log
337342
[error]

0 commit comments

Comments
 (0)