Memory leak when connection failed

Vitaly BerovVitaly Berov Member Vitaly BerovOrganization: Nival OnlineProject: MMO project
Hello,

I have a code like this:
try
{
Ice::ObjectPrx base = ic->stringToProxy( "Test:tcp -p 9326");
::frontEnd::netIce::ServerPrx server = ::frontEnd::netIce::ServerPrx::checkedCast( base );
return 0;
);
}
catch ( Ice::Exception &ex )
{
// couldn't connect to server
return 0;
}

The problem is when we can't connect to server (Ice::ConnectionRefusedException is thrown) I have a memory leak. If I write return 0 just after the line
Ice::ObjectPrx base = ic->stringToProxy( "Test:tcp -p 9326");
I don't have any memory leaks.

I suspect that I work with Ice incorrectly in some way. Could you explain, what is wrong?

Vitaly Berov

Comments

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    Your code looks fine. Do you have more information on the leak? What platform and Ice version do you use? Also, what tool do you use to figure memory leaks? There's no known memory leaks in Ice.

    Cheers,
    Benoit.
  • Vitaly BerovVitaly Berov Member Vitaly BerovOrganization: Nival OnlineProject: MMO project
    Hi, Benoit

    We've found a problem. We use MSVC2005 and we had "enable C++ exception" option switched off. Compiler issued some warnings and compiled our code successfully.
    But it didn't called destructors when unwound exceptions. So "Ice::ObjectPrx base" destructor never called -> not all references at "ic" were released -> we had memory leaks.

    Sorry for disturbance and be on the watch for warnings! :)

    Vitaly Berov
Sign In or Register to comment.