提交 0c9956f8 编写于 作者: P Paolo Bonzini

test-char: fix AddressSanitizer failure

The CharSocketServerTestConfig and CharSocketClientTestConfig
objects escape after they are passed to g_test_add_data_func,
but they cease existing after the scope that defines them is
closed.  Make them static to fix this issue.

Fixes: e7b6ba41Reviewed-by: NPhilippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 f64f598a
...@@ -1355,6 +1355,18 @@ static void char_hotswap_test(void) ...@@ -1355,6 +1355,18 @@ static void char_hotswap_test(void)
g_free(chr_args); g_free(chr_args);
} }
static SocketAddress tcpaddr = {
.type = SOCKET_ADDRESS_TYPE_INET,
.u.inet.host = (char *)"127.0.0.1",
.u.inet.port = (char *)"0",
};
#ifndef WIN32
static SocketAddress unixaddr = {
.type = SOCKET_ADDRESS_TYPE_UNIX,
.u.q_unix.path = (char *)"test-char.sock",
};
#endif
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
bool has_ipv4, has_ipv6; bool has_ipv4, has_ipv6;
...@@ -1390,26 +1402,14 @@ int main(int argc, char **argv) ...@@ -1390,26 +1402,14 @@ int main(int argc, char **argv)
g_test_add_func("/char/file-fifo", char_file_fifo_test); g_test_add_func("/char/file-fifo", char_file_fifo_test);
#endif #endif
SocketAddress tcpaddr = {
.type = SOCKET_ADDRESS_TYPE_INET,
.u.inet.host = (char *)"127.0.0.1",
.u.inet.port = (char *)"0",
};
#ifndef WIN32
SocketAddress unixaddr = {
.type = SOCKET_ADDRESS_TYPE_UNIX,
.u.q_unix.path = (char *)"test-char.sock",
};
#endif
#define SOCKET_SERVER_TEST(name, addr) \ #define SOCKET_SERVER_TEST(name, addr) \
CharSocketServerTestConfig server1 ## name = \ static CharSocketServerTestConfig server1 ## name = \
{ addr, false, false }; \ { addr, false, false }; \
CharSocketServerTestConfig server2 ## name = \ static CharSocketServerTestConfig server2 ## name = \
{ addr, true, false }; \ { addr, true, false }; \
CharSocketServerTestConfig server3 ## name = \ static CharSocketServerTestConfig server3 ## name = \
{ addr, false, true }; \ { addr, false, true }; \
CharSocketServerTestConfig server4 ## name = \ static CharSocketServerTestConfig server4 ## name = \
{ addr, true, true }; \ { addr, true, true }; \
g_test_add_data_func("/char/socket/server/mainloop/" # name, \ g_test_add_data_func("/char/socket/server/mainloop/" # name, \
&server1 ##name, char_socket_server_test); \ &server1 ##name, char_socket_server_test); \
...@@ -1421,17 +1421,17 @@ int main(int argc, char **argv) ...@@ -1421,17 +1421,17 @@ int main(int argc, char **argv)
&server4 ##name, char_socket_server_test) &server4 ##name, char_socket_server_test)
#define SOCKET_CLIENT_TEST(name, addr) \ #define SOCKET_CLIENT_TEST(name, addr) \
CharSocketClientTestConfig client1 ## name = \ static CharSocketClientTestConfig client1 ## name = \
{ addr, NULL, false, false }; \ { addr, NULL, false, false }; \
CharSocketClientTestConfig client2 ## name = \ static CharSocketClientTestConfig client2 ## name = \
{ addr, NULL, true, false }; \ { addr, NULL, true, false }; \
CharSocketClientTestConfig client3 ## name = \ static CharSocketClientTestConfig client3 ## name = \
{ addr, ",reconnect=1", false }; \ { addr, ",reconnect=1", false }; \
CharSocketClientTestConfig client4 ## name = \ static CharSocketClientTestConfig client4 ## name = \
{ addr, ",reconnect=1", true }; \ { addr, ",reconnect=1", true }; \
CharSocketClientTestConfig client5 ## name = \ static CharSocketClientTestConfig client5 ## name = \
{ addr, NULL, false, true }; \ { addr, NULL, false, true }; \
CharSocketClientTestConfig client6 ## name = \ static CharSocketClientTestConfig client6 ## name = \
{ addr, NULL, true, true }; \ { addr, NULL, true, true }; \
g_test_add_data_func("/char/socket/client/mainloop/" # name, \ g_test_add_data_func("/char/socket/client/mainloop/" # name, \
&client1 ##name, char_socket_client_test); \ &client1 ##name, char_socket_client_test); \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册