You have already done it...
Look at how you declare your 'request':
Request *request=new Request();
So 'request' is now allocated on the heap.. means you are responsible for cleaning it up (delete request; somewhere in the code).
Then, you say.. ok I want 'request' to point to a LoginRequest.
LoginRequest loginRequest;
request=&loginRequest;
So you are overwriting the previous pointer to 'new Request();' with a pointer to a local variable loginRequest.
Since loginRequest is local, it will be destroyed when it goes out of scope. Now your 'request' pointer points to garbage and there is no way that you can delete the original new Request()(remember you overwrote the pointer), so you have yourself a memory leak.
So I dont really understand why you do the first "new Request();".. doesnt this make more sense:
Request *request=new LoginRequest(); // I guess LoginRequests inherits from Request?
request->tcpMessage=line.toUtf8();
request->decodeFromTcpMessage();
if(request->requestType==REQUEST_LOGIN)
{
requests.enqueue(request);
} else // Request is not a LOGIN_REQUEST
{
delete request;
}
// When you destroy the requests.. dont forget to delete the pointers.
P.S. think about your naming convention...
Is using 'requests' and 'request' a good idea? The names look very simmilar and just introduce confusion.