nikhilm / qhttpserver

HTTP server implementation for Qt based on node.js' http parser

Home Page:http://kodeclutz.blogspot.com/2011/02/qhttpserver-web-apps-in-qt.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Leaking QHttpRequest objects

martinky opened this issue · comments

The request object passed to the QHttpServer::newRequest(QHttpRequest*, QHttpResponse*) signal is never deleted. Neither the code samples, nor the inline documentation suggest that the user is responsible for deleting the request.

I suggest that the request object should be deleted automatically when the response is deleted:

connect(response, SIGNAL(destroyed(), request, SLOT(deleteLater()));

Further, if the user fails to connect and properly handle the newRequest() signal, both request and response (and connection) objects will leak. The response and connection objects are destroyed when the connection is closed by the client, but the request is never destroyed. I suggest passing these objects wrapped in a QSharedPointer rather than naked pointers. That would make the API safe(r) by design.

Nice library thou, thank you for sharing 👍

The docs do suggest that.

QHttpRequest is never deleted by QHttpServer. Since it is not possible to determine till what point the application may want access to its data, it is up to the application to delete it. A recommended way to handle this is to create a new responder object for every request and to delete the request in that object's destructor. The object itself can be deleted by connecting to QHttpResponse's done() slot as explained below.

But I like your idea.