|
我想用valgrind检查程序中的内存泄露情况,可是我程序都没有办法正常运行了!
我用的是异步的socket,为什么socket会收到乱的东西啊?
不用valgrind启动程序时都是正常的。
1、TCP接收数据时,RD_ISSET一直为true,ER_ISSET为true 数据是0。
2、UDP接收数据时,RD_ISSET一直为true,数据长度不为0,但接收到的数据都是0。
系统:
Linux headend1 2.6.8-24-default #1 Wed Oct 6 09:16:23 UTC 2004 i686 i686 i386 GNU/Linux
headend1:/home/he # gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ./configure
Thread model: posix
gcc version 4.1.0
代码如下:
if (fd > 0 && FD_ISSET(fd,&rd))
{
LOGGER_DEBUG(loggerP, "RD_ISSET");
//have data can be read from fd
if(fd == emsFd)
{
int len = read(fd, cmdBufP->rBuf + cmdBufP->rBufLen,
CMD_RD_BUF_MAX_LEN - cmdBufP->rBufLen);
if (fd > 0 && FD_ISSET(fd,&er))
{
LOGGER_DEBUG(loggerP, "ER_ISSET");
//have error for specified fd
char c;
errno = 0;
int r = recv(fd, &c, 1, MSG_OOB);
if ( r < 1 )
{
//clear error fd_set
FD_CLR(fd,&er);
//have really error
LOGGER_DEBUG(loggerP,"connect to client fd occured problem");
shutdownFd(fd);
return;
}
else
{
//may be have MSG_OOB
LOGGER_DEBUG(loggerP,"received MSG_OOB");
}
sock open:
if ( ( s = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
{
//perror("socket");
LOGGER_ERROR(loggerP,"socket failed");
return -1;
}
yes = -1;
if ( setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)) < 0 )
{
//perror("setsockopt");
LOGGER_ERROR(loggerP,"setsockopt failed");
close(s);
return -1;
}
memset(&a, 0, sizeof(a));
a.sin_port = htons(listenPort);
a.sin_family = AF_INET;
if ( bind(s, (struct sockaddr *)&a, sizeof(a)) < 0 )
{
//perror("bind");
LOGGER_ERROR(loggerP,"bind failed");
close(s);
return -1;
}
char buf[1024];
sprintf(buf,"accepting connections on port %d", listenPort);
LOGGER_INFO(loggerP,buf);
listen(s, 10);
return s;
运行日志如下:
2:40 [CmdTrsvr] RD_ISSET
2:40 [CmdTrsvr] not received one error frame00000
[CmdTrsvr] buffer data:
00 00 00
2:40 [CmdTrsvr] ER_ISSET
2:40 [CmdTrsvr] received MSG_OOB
2:40 [UdpTrsvr] snmp data get:
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00
00 00 00 00 00 00
dTrsvr] buffer data:
--4143-- sigvgkill for lwp 4143 tid 1
00 00 00
--4143-- sigvgkill for lwp 4143 tid 1
00 00 00
--4143-- sigvgkill for lwp 4143 tid 1
--4143-- sigvgkill for lwp 4143 tid 1
--4143-- sigvgkill for lwp 4143 tid 1
dTrsvr] ER_ISSET
--4143-- sigvgkill for lwp 4143 tid 1
vr] ER_ISSET
--4143-- sigvgkill for lwp 4143 tid 1
--4143-- sigvgkill for lwp 4143 tid 1
--4143-- sigvgkill for lwp 4143 tid 1
[CmdTrsvr] received MSG_OOB
++4143++ do_setmask: tid = 1 how = 2 (SIG_SETMASK), set = 0xBEFFF39C 0000000000000000
++4143++ oldset=0xBEFFF29C 8000000000000000
--4143-- poll_signals: got signal 64 for thread 1
--4143-- Polling found signal 64 for tid 1
--4143-- signal 64 ignored
--4143-- sigvgkill for lwp 4143 tid 1
--4143-- poll_signals: got signal 64 for thread 1
--4143-- Polling found signal 64 for tid 1
--4143-- signal 64 ignored
++4143++ do_setmask: tid = 1 how = 2 (SIG_SETMASK), set = 0xBEFFF29C 8000000000000000
--4143-- sigvgkill for lwp 4143 tid 1
--4143-- sigvgkill for lwp 4143 tid 1
--4143-- sigvgkill for lwp 4143 tid 1
6:57 [UdpTrsvr] snmp data get:
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 -- 00 00 00 00 00 00 00 00 |
|