GSoap服务器内存泄漏问题

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()避免这一堆处理。

你可能感兴趣的:(GSoap服务器内存泄漏问题)