version 1.0
2008-11-25
写了个GSoap2.7.10的服务器小程序,代码很简单:RecSoapBindingService svr;
int m = svr.bind(0, 80, 100);
if(m<0)
{
soap_print_fault(&svr, stderr);
return 0;
}
fprintf(stderr, "Socket connection successful: master socket = %d/n", m);
for(;;)
{
m = svr.accept();
if (m < 0)
{
soap_print_fault(&svr, stderr);
exit(-1);
}
fprintf(stderr, "Socket connection successful: slave socket = %d/n", m);
svr.serve();
//break;
}
测试发现有内存泄漏问题:压力测试下看见内存一直在涨,但正常退出(通过在循环中加break使程序正常结束)时内存能够释放完全(VC环境中没有检测到内存泄漏);Debug与Release版本都是这样。
GSoap官方网站上(http://www.cs.fsu.edu/~engelen/soap.html)有一段说明,不知道针对哪个版本:
The gSOAP engine uses a memory management method to allocate and deallocate memory. The deallocation is performed with soap_destroy() followed by soap_end(). However, when you compile with -DDEBUG or -DSOAP_MEM_DEBUG then no memory is released until soap_done() is invoked. This ensures that the gSOAP engine can track all malloced data to verify leaks and double frees in debug mode. Use -DSOAP_DEBUG to use the normal debugging facilities without memory debugging. Note that some compilers have DEBUG enabled in the debug configuration, so this behavior should be expected unless you compile in release config.
于是在 svr.serve();后加入代码:
soap_destroy(&svr);
soap_end(&svr);
问题解决——与说明不符的是,没发现Debug版与Release版的区别。
也可以直接调用svr.run()避免这一堆处理。
在使用GSoap2.7.10构建的服务器程序中,发现存在内存泄漏问题,尤其是在压力测试下内存持续增长。然而,通过在循环中调用`soap_destroy()`和`soap_end()`或者使用`svr.run()`,可以成功解决这个问题。官方文档提到在DEBUG模式下,内存释放需调用`soap_done()`,但在实际测试中,此解决方案在Debug和Release版本都有效。
3131

被折叠的 条评论
为什么被折叠?



