0

I'm using gSOAP under Linux in one of my projects, and I have a problem when using the server for a pretty long time (actually not very long, I get this error after something like 10 hours...). I followed the example gave some time ago here for multithreading in gSOAP. I create a soap service, then use the copy method and pass it to a thread. The thread functions is something like this:

void MyClass::SoapServer(myservice::Service* soapService)
{
    int res = soapService->serve();
    if (res != SOAP_OK)
    {
        // log error
    }
    soapService->destroy();
    soap_free(soapService);
}

After a few hours, when there is a constant poller that calls SOAP functions, I get segmentation fault in the gSOAP copy function. Below i attach the code that accepts the connection and creates the thread.

while(true)
{
    int error = mySoapService.accept();
    if (!soap_valid_socket(error))
{
        //error
    }
    else
    {
        myservice::Service *soapServiceCopy = NULL;
        soapServiceCopy = mySoapService.copy();
        // create thread using the SoapServer function 
        // and pass soapServiceCopy as an argument         
    }
}

It seems to me that the soap service clean up is correctly performed, is there anything I'm missing?

Thanks

Community
  • 1
  • 1
cpl
  • 669
  • 6
  • 23
  • A stack trace showing the problem would help as would details of the version of gsoap you are using and the operating system you are running it under. If you can then I'd suggest running the program under valgrind and seeing what, if anything, that reports. – Jackson Jul 23 '12 at 09:22

1 Answers1

0

The difference between your code and my example that you link to is that you use soap_free() to free the soapService object and my example uses delete. Changing my example code to use soap_free() and then running it under valgrind leads to free / delete / delete[] mismatches being reported which makes me think that soap_free() is built on top of free but the .copy() method is using new to create the copy.

Jackson
  • 5,627
  • 2
  • 29
  • 48
  • I used delete before, but then I noticed that soap_free calls soap_done, which seems to cleanup things a bit. When I used delete I had a similar problem. I'll try to post some details, but the problem is I get this errors after a few hours, so it's not that easy to track... – cpl Jul 23 '12 at 12:15