Mercurial > hg > nginx
comparison src/core/ngx_file.c @ 5316:12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
If a relative path is set by variables, then the ngx_conf_full_name()
function was called while processing requests, which causes allocations
from the cycle pool.
A new function that takes pool as an argument was introduced.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Tue, 06 Aug 2013 19:58:40 +0400 |
parents | c821975c9068 |
children | f1a91825730a |
comparison
equal
deleted
inserted
replaced
5315:31932b5464f0 | 5316:12dd27b74117 |
---|---|
7 | 7 |
8 #include <ngx_config.h> | 8 #include <ngx_config.h> |
9 #include <ngx_core.h> | 9 #include <ngx_core.h> |
10 | 10 |
11 | 11 |
12 static ngx_int_t ngx_test_full_name(ngx_str_t *name); | |
13 | |
14 | |
12 static ngx_atomic_t temp_number = 0; | 15 static ngx_atomic_t temp_number = 0; |
13 ngx_atomic_t *ngx_temp_number = &temp_number; | 16 ngx_atomic_t *ngx_temp_number = &temp_number; |
14 ngx_atomic_int_t ngx_random_number = 123456; | 17 ngx_atomic_int_t ngx_random_number = 123456; |
18 | |
19 | |
20 ngx_int_t | |
21 ngx_get_full_name(ngx_pool_t *pool, ngx_str_t *prefix, ngx_str_t *name) | |
22 { | |
23 size_t len; | |
24 u_char *p, *n; | |
25 ngx_int_t rc; | |
26 | |
27 rc = ngx_test_full_name(name); | |
28 | |
29 if (rc == NGX_OK) { | |
30 return rc; | |
31 } | |
32 | |
33 len = prefix->len; | |
34 | |
35 #if (NGX_WIN32) | |
36 | |
37 if (rc == 2) { | |
38 len = rc; | |
39 } | |
40 | |
41 #endif | |
42 | |
43 n = ngx_pnalloc(pool, len + name->len + 1); | |
44 if (n == NULL) { | |
45 return NGX_ERROR; | |
46 } | |
47 | |
48 p = ngx_cpymem(n, prefix->data, len); | |
49 ngx_cpystrn(p, name->data, name->len + 1); | |
50 | |
51 name->len += len; | |
52 name->data = n; | |
53 | |
54 return NGX_OK; | |
55 } | |
56 | |
57 | |
58 static ngx_int_t | |
59 ngx_test_full_name(ngx_str_t *name) | |
60 { | |
61 #if (NGX_WIN32) | |
62 u_char c0, c1; | |
63 | |
64 c0 = name->data[0]; | |
65 | |
66 if (name->len < 2) { | |
67 if (c0 == '/') { | |
68 return 2; | |
69 } | |
70 | |
71 return NGX_DECLINED; | |
72 } | |
73 | |
74 c1 = name->data[1]; | |
75 | |
76 if (c1 == ':') { | |
77 c0 |= 0x20; | |
78 | |
79 if ((c0 >= 'a' && c0 <= 'z')) { | |
80 return NGX_OK; | |
81 } | |
82 | |
83 return NGX_DECLINED; | |
84 } | |
85 | |
86 if (c1 == '/') { | |
87 return NGX_OK; | |
88 } | |
89 | |
90 if (c0 == '/') { | |
91 return 2; | |
92 } | |
93 | |
94 return NGX_DECLINED; | |
95 | |
96 #else | |
97 | |
98 if (name->data[0] == '/') { | |
99 return NGX_OK; | |
100 } | |
101 | |
102 return NGX_DECLINED; | |
103 | |
104 #endif | |
105 } | |
15 | 106 |
16 | 107 |
17 ssize_t | 108 ssize_t |
18 ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain) | 109 ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain) |
19 { | 110 { |