[Pkg-owncloud-commits] [owncloud-client] 131/498: SocketAPI: Do not leak open DB or query

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 67f7892958b11219da564e3db9bbb1376ce6d86f
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Mon Jun 8 15:49:37 2015 +0200

    SocketAPI: Do not leak open DB or query
    
    We could leak it in case of errors. Or when the folder is removed.
    Make use of QSharedPointer to avoid leaks
---
 src/gui/socketapi.cpp | 13 ++++++-------
 src/gui/socketapi.h   |  4 ++--
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp
index 1a7f641..31c8d07 100644
--- a/src/gui/socketapi.cpp
+++ b/src/gui/socketapi.cpp
@@ -245,14 +245,14 @@ void SocketApi::slotUnregisterPath( const QString& alias )
         broadcastMessage(QLatin1String("UNREGISTER_PATH"), f->path(), QString::null, true );
 
         if( _dbQueries.contains(f)) {
-            SqlQuery *h = _dbQueries[f];
+            auto h = _dbQueries[f];
             if( h ) {
                 h->finish();
             }
             _dbQueries.remove(f);
         }
         if( _openDbs.contains(f) ) {
-            SqlDatabase *db = _openDbs[f];
+            auto db = _openDbs[f];
             if( db ) {
                 db->close();
             }
@@ -476,7 +476,7 @@ SqlQuery* SocketApi::getSqlQuery( Folder *folder )
     }
 
     if( _dbQueries.contains(folder) ) {
-        return _dbQueries[folder];
+        return _dbQueries[folder].data();
     }
 
     /* No valid sql query object yet for this folder */
@@ -487,21 +487,20 @@ SqlQuery* SocketApi::getSqlQuery( Folder *folder )
 
     QFileInfo fi(dbFileName);
     if( fi.exists() ) {
-        SqlDatabase *db = new SqlDatabase;
+        auto db = QSharedPointer<SqlDatabase>::create();
 
         if( db && db->openReadOnly(dbFileName) ) {
             _openDbs.insert(folder, db);
 
-            SqlQuery *query = new SqlQuery(*db);
+            auto query = QSharedPointer<SqlQuery>::create(*db);
             rc = query->prepare(sql);
 
             if( rc != SQLITE_OK ) {
-                delete query;
                 qDebug() << "Unable to prepare the query statement:" << rc;
                 return 0; // do not insert into hash
             }
             _dbQueries.insert( folder, query);
-            return query;
+            return query.data();
         } else {
             qDebug() << "Unable to open db" << dbFileName;
         }
diff --git a/src/gui/socketapi.h b/src/gui/socketapi.h
index 97f7b9a..c39c540 100644
--- a/src/gui/socketapi.h
+++ b/src/gui/socketapi.h
@@ -85,8 +85,8 @@ private:
     QList<QLocalSocket*> _listeners;
     QLocalServer _localServer;
     c_strlist_t *_excludes;
-    QHash<Folder*, SqlQuery*> _dbQueries;
-    QHash<Folder*, SqlDatabase*> _openDbs;
+    QHash<Folder*, QSharedPointer<SqlQuery>> _dbQueries;
+    QHash<Folder*, QSharedPointer<SqlDatabase>> _openDbs;
 };
 
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list