我正在测试ØMQ
以便在我的项目中使用。我从here下载了最新的二进制文件。我使用libzmq-v90-mt-gd-4_0_4.lib
作为预期的项目用途C++ tool-set v90
。现在我创建了一个示例服务器,例如official zero-mq guide中给出的示例和同一guide中给出的客户端代码。服务器代码是:
void zmqServer()
{
// Prepare our context and socket
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REP);
socket.bind("tcp://*:5555");
//int i = 0;
while (true) {
zmq::message_t request;
char buffer[256];
// Wait for next request from client
int size = zmq_recv(socket, buffer, 255, 0);
if (size == -1) continue;
if (size > 255) size = 255;
buffer[size] = 0;
std::string receivedStr = strdup(buffer);
std::cout << "Message # " << i << ": " << receivedStr << std::endl;
// Do some 'work'
sleep(1);
// Send reply back to client
zmq::message_t reply(5);
std::string msg = "Server#" + receivedStr;
std::cout << "Reply # " << i << ": " << msg << std::endl;
memcpy(reply.data(), msg.c_str(), msg.length());
socket.send(reply);
//i++;
}
}
客户端代码是:
void zmqClient()
{
// Prepare our context and socket
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REQ);
std::cout << "Connecting to hello world server..." << std::endl;
socket.connect("tcp://localhost:5555");
// Do 10 requests, waiting each time for a response
for (int request_nbr = 0; request_nbr != 10; request_nbr/*++ removed to loop forever to test*/) {
std::string msg = "HELLO FROM CLIENT";
zmq::message_t request(msg.length());
memcpy(request.data(), msg.c_str(), msg.length());
std::cout << "Sending Request#: " << request_nbr << "\nMessage: " << msg << std::endl;
socket.send(request);
// Get the reply.
zmq::message_t reply;
socket.recv(&reply);
std::cout << "Received World " << request_nbr << std::endl;
}
}
在服务器端,Windows诊断工具(vs-2015)快照一次是:
稍后的另一个快照是:
可以看到两次之间的记忆差异。关于另一次运行,在20个服务器程序连接之后,Visual Leak Detector
报告是:
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 7 at 0x0171DFE8: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 10 at 0x0171E0E8: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 17 at 0x0171E128: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 19 at 0x0171E1A8: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 13 at 0x0171E228: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 14 at 0x0171E2E8: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 1 at 0x0171E368: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 6 at 0x0171E3A8: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 15 at 0x0171E3E8: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 16 at 0x0171E428: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 20 at 0x0171E468: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 4 at 0x0171E4E8: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 11 at 0x0171E528: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 2 at 0x0171E5A8: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 5 at 0x0171E5E8: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 12 at 0x0171E628: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 18 at 0x0171E668: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 3 at 0x0171E6E8: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 8 at 0x0171E728: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
---------- Block 9 at 0x0171E768: 18 bytes ----------
Leak Hash: 0x90285749, Count: 1, Total 18 bytes
Call Stack (TID 5340):
MSVCR90D.dll!strdup()
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (46): ZeroMQServer.exe!zmqServer() + 0xF bytes
c:\users\awais\documents\visual studio 2015\projects\zeromqserver\zeromqserver\zmq_server.cpp (20): ZeroMQServer.exe!main()
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (582): ZeroMQServer.exe!__tmainCRTStartup() + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): ZeroMQServer.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
48 45 4C 4C 4F 20 46 52 4F 4D 20 43 4C 49 45 4E HELLO.FR OM.CLIEN
54 00 T....... ........
Visual Leak Detector detected 20 memory leaks (1080 bytes).
Largest number used: 1080 bytes.
Total allocations: 1080 bytes.
Visual Leak Detector is now exiting.
可以看到每个连接都有内存泄漏。在这种情况下,任何建议谁是罪魁祸首?是memcpy()
有点像其他人,我发现有关zero-mq memory leak的讨论。任何克服这种情况的建议都将受到高度赞赏。
修改
memcpy()
也在客户端使用,但 Visual Leak Detector 未报告内存泄漏。