内存泄漏???求高人

客户端代码,重点就是析构函数中的free。为什么一free就提示内存泄漏。 后面有valgrind内存分析。说是地址不可用??求高人解答,到底出错在哪??

NtClient::NtClient()
{
memset(&m_servAddr, 0, sizeof(struct sockaddr_in));
m_servAddr.sin_family = AF_INET;
m_servAddr.sin_port = htons(6606);
inet_aton("127.0.0.1", reinterpret_cast(&m_servAddr.sin_addr.s_addr));

int m_clientFd = -1;

m_receBuffer = (char*)malloc(100);
printf("m_receBuffer = %p\n", m_receBuffer);

}

NtClient::~NtClient()
{
printf("m_receBuffer = %p\n", m_receBuffer);
free(m_receBuffer2); //打开就泄漏,关闭没问题
m_receBuffer = NULL;
}

int NtClient::start()
{
int iRet = -1;

//1.socket创建
int m_clientFd = socket(AF_INET, SOCK_STREAM, 0);
if(m_clientFd < 0)
{
    printf("Socket init error!\n");
    return -1;
}
//2.connect
iRet = connect(m_clientFd, (struct sockaddr*)&m_servAddr, sizeof(m_servAddr));
if(iRet < 0)
{
    printf("%s---", strerror(errno));
    printf("Connect error!\n");
    return -1;
}
//3.recv||send
iRet = recv(m_clientFd, m_receBuffer, 100*sizeof(m_receBuffer), 0);
if(iRet < 0)
{
    printf("Recv error!\n");
    return -1;
}
else
{
    printf("%s---", strerror(errno));
    printf("recvNum=%d, recvData= %s\n", iRet, m_receBuffer);
}
//4.close
//close(m_clientFd);

return 0;

}

pcm@ubuntu:~/Desktop/cs1$ valgrind --tool=memcheck --leak-check=full ./a.out
==5430== Memcheck, a memory error detector
==5430== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==5430== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==5430== Command: ./a.out
==5430==
m_receBuffer = 0x5a02040
==5430== Syscall param socketcall.recvfrom(buf) points to unaddressable byte(s)
==5430== at 0x543C2C2: recv (recv.c:30)
==5430== by 0x4011AD: NtClient::start() (in /home/pcm/Desktop/cs1/a.out)
==5430== by 0x400C83: main (in /home/pcm/Desktop/cs1/a.out)
==5430== Address 0x5a020a4 is 0 bytes after a block of size 100 alloc'd
==5430== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5430== by 0x401092: NtClient::NtClient() (in /home/pcm/Desktop/cs1/a.out)
==5430== by 0x400C77: main (in /home/pcm/Desktop/cs1/a.out)
==5430==
Success---recvNum=400, recvData= Service_return_ok!

program!
m_receBuffer = 0x5a02040
==5430==
==5430== HEAP SUMMARY:
==5430== in use at exit: 0 bytes in 0 blocks
==5430== total heap usage: 1 allocs, 1 frees, 100 bytes allocated
==5430==
==5430== All heap blocks were freed -- no leaks are possible
==5430==
==5430== For counts of detected and suppressed errors, rerun with: -v
==5430== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
pcm@ubuntu:~/Desktop/cs1$

我是提问者,free(m_receBuffer2); //打开就泄漏,关闭没问题 。 应该是 free(m_receBuffer);我测试用上传代码时忘了改了这个问题请忽略,不是导致 问题的原因。

iRet = recv(m_clientFd, m_receBuffer, 100*sizeof(m_receBuffer), 0);
改成
iRet = recv(m_clientFd, m_receBuffer, 100*sizeof(char), 0);

m_receBuffer只有100个字节,100*sizeof(m_receBuffer),四字节指针的话,这里是400,越界了