[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [solid] src/solid/devices/backends/iokit: fix a leak and incorrect nullptr check in DADictionary.
From:       R.J.V. Bertin <null () kde ! org>
Date:       2018-03-01 13:11:21
Message-ID: E1erNzV-000766-HH () code ! kde ! org
[Download RAW message or body]

Git commit 3642f7c6a329ac807ef9294273d7139e0ae6e366 by R.J.V. Bertin.
Committed on 01/03/2018 at 13:10.
Pushed by rjvbb into branch 'master'.

fix a leak and incorrect nullptr check in DADictionary.

Also adds some comments.

M  +6    -2    src/solid/devices/backends/iokit/dadictionary.cpp
M  +23   -0    src/solid/devices/backends/iokit/dadictionary_p.h

https://commits.kde.org/solid/3642f7c6a329ac807ef9294273d7139e0ae6e366

diff --git a/src/solid/devices/backends/iokit/dadictionary.cpp \
b/src/solid/devices/backends/iokit/dadictionary.cpp index af9d3de..2c53b4e 100644
--- a/src/solid/devices/backends/iokit/dadictionary.cpp
+++ b/src/solid/devices/backends/iokit/dadictionary.cpp
@@ -50,10 +50,13 @@ DADictionary::~DADictionary()
 
 bool DADictionary::getDict()
 {
+    // daDict may cache the latest disk description dict;
+    // we will refresh it now.
+    releaseDict();
     if (daRef) {
         daDict = DADiskCopyDescription(daRef);
     }
-    return daRef != nullptr;
+    return daDict != nullptr;
 }
 
 void DADictionary::releaseDict()
@@ -69,8 +72,8 @@ const QString DADictionary::stringForKey(const CFStringRef key)
     QString ret;
     if (getDict()) {
         ret = QString::fromCFString((const CFStringRef) CFDictionaryGetValue(daDict, \
key)); +        releaseDict();
     }
-    releaseDict();
     return ret;
 }
 
@@ -92,6 +95,7 @@ bool DADictionary::boolForKey(const CFStringRef key, bool &value)
         if (boolRef) {
             value = CFBooleanGetValue(boolRef);
         }
+        releaseDict();
         return boolRef != nullptr;
     }
     return false;
diff --git a/src/solid/devices/backends/iokit/dadictionary_p.h \
b/src/solid/devices/backends/iokit/dadictionary_p.h index 28cfc7f..b8d4133 100644
--- a/src/solid/devices/backends/iokit/dadictionary_p.h
+++ b/src/solid/devices/backends/iokit/dadictionary_p.h
@@ -40,10 +40,33 @@ public:
     DADictionary(const IOKitDevice *device);
     virtual ~DADictionary();
 
+    /**
+     * get a fresh copy of the DA disk description dict;
+     * the result is stored in daRef (after releasing any
+     * dict it may currently point to).
+     */
     bool getDict();
+    /**
+     * release the DA disk description dict and reset daRef.
+     */
     void releaseDict();
+
+    /**
+     * fetch the value of @p key as a string, from the current
+     * disk description (calls getDict() and releaseDict()).
+     */
     const QString stringForKey(const CFStringRef key);
+    /**
+     * fetch the value of @p key as a CFURLRef, from the current
+     * disk description. Calls getDict() but not releaseDict().
+     *The contents of the CFURLRef must be retrieved before
+     * calling releaseDict() (and thus getDict()).
+     */
     CFURLRef cfUrLRefForKey(const CFStringRef key);
+    /**
+     * fetch the value of @p key as a boolean, from the current
+     * disk description (calls getDict() and releaseDict()).
+     */
     bool boolForKey(const CFStringRef key, bool &value);
 
     const IOKitDevice *device;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic