GSoap服务器内存泄漏问题

来源:互联网 发布:远程服务器端口 编辑:程序博客网 时间:2024/06/06 03:22
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 managementmethod to allocate and deallocate memory. The deallocation is performed withsoap_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. Thisensures that the gSOAP engine can track all malloced data to verify leaks anddouble frees in debug mode. Use -DSOAP_DEBUG to use the normal debuggingfacilities without memory debugging. Note that some compilers have DEBUGenabled in the debug configuration, so this behavior should be expected unlessyou compile in release config.

        于是在
svr.serve();后加入代码:
        soap_destroy(&svr);
        soap_end(&svr);

        问题解决——与说明不符的是,没发现Debug版与Release版的区别。

        也可以直接调用
svr.run()避免这一堆处理。

原创粉丝点击