Many test programs deletes services twice

Issue #12 resolved
Jochen Becher created an issue

Calling QJsonRpcAbstractServer::addService adds the given service to a QObjectCleanupHandler instance which will delete all added services in its destructor. Thus a new service must be allocated on heap and may not be deleted manually or it must be declared after the server object (which will remove it automatically from the server's QObjectCleanupHandler instance when the service is automatically destructed before the server).

Comments (4)

  1. Matt Broadstone

    Can you describe which tests you think do this? Most of the qjsonrpc*server tests start init each test with a new server, and then do a server->addService(new TestService). Last time I used valgrind on the tests there were no memory leaks or double deletions.

  2. Jochen Becher reporter

    This is tcpserver.cpp from manual tests which declares service before server. If I run it twice the second instance crashes on returning -1.

    #include <QCoreApplication>
    
    #include "qjsonrpctcpserver.h"
    #include "testservice.h"
    
    int main(int argc, char **argv)
    {
        QCoreApplication app(argc, argv);
        TestService service;
        QJsonRpcTcpServer rpcServer;
        rpcServer.addService(&service);
        if (!rpcServer.listen(QHostAddress::LocalHost, 5555)) {
            qDebug() << "can't start tcp server: " << rpcServer.errorString();
            return -1;
        }
    
        return app.exec();
    }
    

    localserver.cpp has a similar problem.

  3. Matt Broadstone

    ah.. manual tests, yeah I don't automatically run those :) I'll take a look later today, thanks

  4. Log in to comment