Mercurial > hg > nginx-quic
annotate src/os/win32/ngx_shmem.c @ 5659:3fb6615bb87f
Upstream: plugged potential memory leak on reload.
The SSL_CTX_set_cipher_list() may fail if there are no valid ciphers
specified in proxy_ssl_ciphers / uwsgi_ssl_ciphers, resulting in
SSL context leak.
In theory, ngx_pool_cleanup_add() may fail too, but this case is
intentionally left out for now as it's almost impossible and proper fix
will require changes to http ssl and mail ssl code as well.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 18 Apr 2014 20:13:24 +0400 |
parents | b3d4e9c66e24 |
children | af7eba90645d |
rev | line source |
---|---|
605 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
605 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 | |
11 | |
12 ngx_int_t | |
13 ngx_shm_alloc(ngx_shm_t *shm) | |
14 { | |
2903
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
15 u_char *name; |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
16 uint64_t size; |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
17 |
4570
b3d4e9c66e24
Win32: fixed memory allocation for shmem name (ticket #134).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
18 name = ngx_alloc(shm->name.len + 2 + NGX_INT32_LEN, shm->log); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
19 if (name == NULL) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
20 return NGX_ERROR; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
21 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
22 |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
23 (void) ngx_sprintf(name, "%V_%s%Z", &shm->name, ngx_unique); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
24 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
25 ngx_set_errno(0); |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
26 |
2903
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
27 size = shm->size; |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
28 |
605 | 29 shm->handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, |
2903
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
30 (u_long) (size >> 32), |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
31 (u_long) (size & 0xffffffff), |
beb0707ed8ab
allow shared memory segments more than 4G
Igor Sysoev <igor@sysoev.ru>
parents:
2737
diff
changeset
|
32 (char *) name); |
605 | 33 |
34 if (shm->handle == NULL) { | |
35 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
2716
d5896f6608e8
move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
605
diff
changeset
|
36 "CreateFileMapping(%uz, %s) failed", |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
37 shm->size, name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
38 ngx_free(name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
39 |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
40 return NGX_ERROR; |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
41 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
42 |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
43 ngx_free(name); |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
44 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
45 if (ngx_errno == ERROR_ALREADY_EXISTS) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
46 shm->exists = 1; |
605 | 47 } |
48 | |
49 shm->addr = MapViewOfFile(shm->handle, FILE_MAP_WRITE, 0, 0, 0); | |
50 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
51 if (shm->addr != NULL) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
52 return NGX_OK; |
605 | 53 } |
54 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
55 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
56 "MapViewOfFile(%uz) of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
57 shm->size, &shm->name); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
58 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
59 if (CloseHandle(shm->handle) == 0) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
60 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
61 "CloseHandle() of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
62 &shm->name); |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
63 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
64 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
65 return NGX_ERROR; |
605 | 66 } |
67 | |
68 | |
69 void | |
70 ngx_shm_free(ngx_shm_t *shm) | |
71 { | |
72 if (UnmapViewOfFile(shm->addr) == 0) { | |
73 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
74 "UnmapViewOfFile(%p) of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
75 shm->addr, &shm->name); |
605 | 76 } |
77 | |
78 if (CloseHandle(shm->handle) == 0) { | |
79 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
2904
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
80 "CloseHandle() of file mapping \"%V\" failed", |
474a9daf8c80
*) fix memory leak in successful case
Igor Sysoev <igor@sysoev.ru>
parents:
2903
diff
changeset
|
81 &shm->name); |
605 | 82 } |
83 } |