fix leaks in SkConf
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 31 Jan 2014 17:32:03 +0000 (17:32 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 31 Jan 2014 17:32:03 +0000 (17:32 +0000)
These leaks were small and would only happen with non-default
runtime configuration things set, but they were still leaks
and they should be squished.

Valgrind reported leaks pre-patch, and all the rtconf leaks are gone after patch.

BUG=skia:1722
R=reed@google.com

Author: humper@google.com

Review URL: https://codereview.chromium.org/136963004

git-svn-id: http://skia.googlecode.com/svn/trunk@13269 2bbb7eff-a529-9590-31e7-b0007b416f81

include/utils/SkRTConf.h
src/utils/SkRTConf.cpp

index 37e3259..4ba6070 100644 (file)
@@ -74,6 +74,7 @@ protected:
 class SkRTConfRegistry {
 public:
     SkRTConfRegistry();
+    ~SkRTConfRegistry();
     void printAll(const char *fname = NULL) const;
     bool hasNonDefault() const;
     void printNonDefault(const char *fname = NULL) const;
index b871374..bb6cb23 100644 (file)
@@ -44,8 +44,8 @@ SkRTConfRegistry::SkRTConfRegistry(): fConfs(100) {
             continue;
         }
 
-        SkString* key = new SkString(keyptr);
-        SkString* val = new SkString(valptr);
+        SkString* key = SkNEW_ARGS(SkString,(keyptr));
+        SkString* val = SkNEW_ARGS(SkString,(valptr));
 
         fConfigFileKeys.append(1, &key);
         fConfigFileValues.append(1, &val);
@@ -53,6 +53,20 @@ SkRTConfRegistry::SkRTConfRegistry(): fConfs(100) {
     sk_fclose(fp);
 }
 
+SkRTConfRegistry::~SkRTConfRegistry() {
+    ConfMap::Iter iter(fConfs);
+    SkTDArray<SkRTConfBase *> *confArray;
+
+    while (iter.next(&confArray)) {
+        delete confArray;
+    }
+
+    for (int i = 0 ; i < fConfigFileKeys.count() ; i++) {
+        SkDELETE(fConfigFileKeys[i]);
+        SkDELETE(fConfigFileValues[i]);
+    }
+}
+
 const char *SkRTConfRegistry::configFileLocation() const {
     return "skia.conf"; // for now -- should probably do something fancier like home directories or whatever.
 }