Skip to content

Commit 6880285

Browse files
committed
* MDF [test] Member variables are initialized at the start of the test
Signed-off-by: Moi Ran <maoyi.ran@emqx.io>
1 parent cca5267 commit 6880285

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/sp/protocol/mqtt/auth_http_test.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,44 @@
33

44
static void conf_auth_http_init(conf_auth_http **conf)
55
{
6-
*conf = nng_alloc(sizeof(conf_auth_http));
6+
*conf = nng_zalloc(sizeof(conf_auth_http));
77
if (*conf == NULL) {
88
return;
99
}
10-
(*conf)->enable = true;
11-
(*conf)->acl_req.header_count = 0;
10+
11+
// Explicitly initialize key fields to avoid using uninitialized
12+
// cache_ttl/acl_cache_mtx in nmq_auth_http_sub_pub during tests.
13+
(*conf)->enable = true;
14+
(*conf)->timeout = 0;
15+
(*conf)->connect_timeout = 0;
16+
(*conf)->pool_size = 0;
17+
(*conf)->cache_ttl = 0; // Ensure ACL cache branch is skipped
18+
(*conf)->acl_cache_map = NULL;
19+
(*conf)->acl_cache_mtx = NULL; // No mutex allocated when cache_ttl is 0
20+
21+
(*conf)->auth_req.enable = false;
22+
(*conf)->auth_req.url = NULL;
23+
(*conf)->auth_req.method = NULL;
1224
(*conf)->auth_req.header_count = 0;
25+
(*conf)->auth_req.headers = NULL;
26+
(*conf)->auth_req.param_count = 0;
27+
(*conf)->auth_req.params = NULL;
28+
29+
(*conf)->super_req.enable = false;
30+
(*conf)->super_req.url = NULL;
31+
(*conf)->super_req.method = NULL;
32+
(*conf)->super_req.header_count = 0;
33+
(*conf)->super_req.headers = NULL;
34+
(*conf)->super_req.param_count = 0;
35+
(*conf)->super_req.params = NULL;
36+
37+
(*conf)->acl_req.enable = false;
38+
(*conf)->acl_req.url = NULL;
39+
(*conf)->acl_req.method = NULL;
40+
(*conf)->acl_req.header_count = 0;
41+
(*conf)->acl_req.headers = NULL;
42+
(*conf)->acl_req.param_count = 0;
43+
(*conf)->acl_req.params = NULL;
1344

1445
return;
1546
}

0 commit comments

Comments
 (0)