View Single Post
  #1 (permalink)  
Old 05-07-2008
Andrew S Andrew S is offline
Registered User
 
Name: Andrew Solodovnikov
Organization: Moscow State technical University
Project: simple grid-like system
 
Join Date: Feb 2008
Posts: 14
Documentation bug (C++ argument calculation order && exception safety)

Hi.

I found a really strange thing in documentation:

Quote:
It is also worth noting that the preceding code does not contain a memory
leak.6 It is OK to pass the pointer returned by new as an argument to add:
Code:
CommunicatorPtr comm = c.adapter->getCommunicator();
c.adapter->add(new PhoneEntryI(name, phNum),
comm->stringToIdentity(name));
This does not cause a problem because add’s formal parameter type for the
servant is const Ice::ObjectPtr&, and ObjectPtr has a single-argument
constructor that accepts an Object*
But surely, this code contains potential memory leak. C++ doesn't restrict argument calculation order, so it can be executed in such sequence:

1. new PhoneEntryI(name, phNum);
2. comm->stringToIdentity(name));
3. ObjectPtr(PhoneEntryI *)

if step (2) generates exception (i look at stringToIdentity code and see that this is really possible), it causes a memory leak.

Please, fix it, at least, in documentation
Reply With Quote