#239 HTTPServer::HTTPServer should take AutoPtr<HTTPServerParams>

Feature_Request
closed
nobody
Net (141)
5
2012-09-14
2009-02-25
Anonymous
No

HTTPServer::HTTPServer should take a AutoPtr<HTTPServerParams> argument instead of a raw HTTPServerParams* argument. Consider what happens in the following code snippet:

HTTPServerParams* params = new HTTPServerParams;
params->setMaxThreads( -42 );
ServerSocket socket();
HTTPServer server( my_handler, socket, params );

In this case, params->setMaxThreads() will throw an exception, which means that the HTTPServerParams object will be leaked. The obvious fix would be to declare an AutoPtr<HTTPServerParams> instead of a raw pointer, but alas, it still needs to be passed to HTTPServer::HTTPServer as a raw pointer, thus defeating the purose. There are workarounds to ensure that the HTTPServerParams object is freed if an exception is thrown before the HTTPServer object takes ownership, but they are complicated and difficult.

Thanks,

Evan <emezeske zzz@zzz="" sunedison="" zzz.zzz="" com="">

Discussion

  • fixed in 1.3.4/svn trunk rev. 1102