2009/6/11 Kevin Regan:
> Let's take as an example, the function in question:
> DBDriver::set_option(Option* o)
> std::ostringstream os;
> std::auto_ptr<Option> cleanup(o);
> Now, let's imagine that the constructor for std::ostringstream can throw an exception
> (maybe it allocates a working buffer). In that event, the memory for the option will
> not be reclaimed when a std::bad_alloc exception is thrown.
The ostringtream default constructor shouldn't throw, but it wouldn't
hurt to swap those two lines so that the pointer is guarded
I detest raw pointers to dynamically allocated memory, and would
advise using an auto_ptr in the interface, so it is explicit that
ownership is being transferred and that the address of a static or
local variable should not be passed in.
The existing function could then be changed to simply forward to that
one, and ideally deprecated.