Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Understanding memory leak
Forum Updated to NodeBB v4.3 + New Features

Understanding memory leak

Scheduled Pinned Locked Moved General and Desktop
qwidgetqsql
1 Posts 1 Posters 793 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lucaghera
    wrote on 8 Oct 2015, 10:51 last edited by
    #1

    I would like to build a GUI that interact with a database.
    When running my application with valgrind I have several leaks and errors.

    I decided therefore to test some simple example and my Eclipse valgrind plugin showed me that the leaks and error come from the same instructions in both my application and the simple examples.

    I report them here and I would like to ask you if you can explain me the reason for these leaks and errors.

    The first example relates to the GUI. This is the code of the simple example It is taken from the Qt for beginners wiki

    int main(int argc, char *argv[]) {
    
    	 QApplication app(argc, argv);
    
    	QWidget window;
    	window.setFixedSize(100, 50);
    
    	QPushButton *button = new QPushButton("Hello World", &window);
    	button->setGeometry(10, 10, 80, 30);
    
    	window.show();
    	return app.exec();
    
    }
    

    I did't expect this application to do anything fancy but I didn't expect memory errors.
    The eclipse Valgrind plugin shows error on the lines:

    • QApplication app (argc, arg): Conditional jump or move depends on uninitialised value(s) [PID: 112960]
    • window.show(): 1 bytes in 1 blocks are definitely lost in loss record 9 of 8,627 [PID: 112960]
    • return app.exec(): Conditional jump or move depends on uninitialised value(s) [PID: 112960]

    The other example related to the DB:

    int main(int argc, char **argv) {
    
    	{
    		QSqlDatabase dbConnection = QSqlDatabase::addDatabase("QPSQL");
    		dbConnection.setHostName("localhost");
    		dbConnection.setDatabaseName("test");
    		dbConnection.setUserName("test");
    		dbConnection.setPassword("test");
    		dbConnection.setPort(5432);
    
    		if (dbConnection.isOpen()) {
    			return true;
    		}
    
    		if (dbConnection.open()) {
    			std::cout << "Connection with the database open" << std::endl;
    		} else {
    			std::cout << "Open DB connection failed:" << std::endl;
    			std::cout << dbConnection.lastError().text().toStdString();
    			return false;
    		}
    	}
    
    	QString dbName = QSqlDatabase::database().connectionName();
    	QSqlDatabase::database().close();
    	QSqlDatabase::removeDatabase(dbName);
    
    }
    

    In this case I get errors on the line dbConnection.open():

    • 39,328 (736 direct, 38,592 indirect) bytes in 1 blocks are definitely lost in loss record 296 of 297 [PID: 114915]
    • 1,640 bytes in 1 blocks are definitely lost in loss record 279 of 297 [PID: 114915]
    • 3,272 (200 direct, 3,072 indirect) bytes in 1 blocks are definitely lost in loss record 289 of 297 [PID: 114915]

    I'm using Qt 5.5 installed with the Qt installer under Ubuntu 12.04.

    Please let me know if you need the complete valgrind log. I have it but uploading them might ruin the readability of the post.

    Thanks!
    Luca

    1 Reply Last reply
    0

    1/1

    8 Oct 2015, 10:51

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved