summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-12-08 17:52:10 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-12-08 17:52:10 +0900
commit9d7bb9d01af2c0ef1b748ac2e240b20439285fd4 (patch)
tree32032f76f7040856ee7d22370be1bd49eb507c98 /src
parenta8641b0998af7b2a5876a77d4f18c9a78230d6b1 (diff)
Release statically allocated resources for prefs and options
Not realeasing these resources does not hurt the correctness of the program, but memory leak detection tool, such as valgrind, reports it as potential memory leak. It is better to distinguish it from the real ones.
Diffstat (limited to 'src')
-rw-r--r--src/OptionParser.cc5
-rw-r--r--src/OptionParser.h3
-rw-r--r--src/Platform.cc8
-rw-r--r--src/prefs.cc12
-rw-r--r--src/prefs.h4
5 files changed, 31 insertions, 1 deletions
diff --git a/src/OptionParser.cc b/src/OptionParser.cc
index d2250374..157d74ec 100644
--- a/src/OptionParser.cc
+++ b/src/OptionParser.cc
@@ -347,4 +347,9 @@ const SharedHandle<OptionParser>& OptionParser::getInstance()
return optionParser_;
}
+void OptionParser::deleteInstance()
+{
+ optionParser_.reset();
+}
+
} // namespace aria2
diff --git a/src/OptionParser.h b/src/OptionParser.h
index 617712db..2cd9f8e7 100644
--- a/src/OptionParser.h
+++ b/src/OptionParser.h
@@ -94,6 +94,9 @@ public:
const OptionHandler* findByShortName(char shortName) const;
static const SharedHandle<OptionParser>& getInstance();
+ // Deletes statically allocated instace. Call this at the end of the
+ // program.
+ static void deleteInstance();
};
} // namespace aria2
diff --git a/src/Platform.cc b/src/Platform.cc
index a2749a4e..298294ae 100644
--- a/src/Platform.cc
+++ b/src/Platform.cc
@@ -73,6 +73,8 @@
#include "message.h"
#include "fmt.h"
#include "console.h"
+#include "OptionParser.h"
+#include "prefs.h"
#ifdef HAVE_LIBGMP
# include "a2gmp.h"
#endif // HAVE_LIBGMP
@@ -172,7 +174,11 @@ bool Platform::tearDown()
#ifdef HAVE_WINSOCK2_H
WSACleanup();
#endif // HAVE_WINSOCK2_H
-
+ // Deletes statically allocated resources. This is done to
+ // distinguish memory leak from them. This is handly to use
+ // valgrind.
+ OptionParser::deleteInstance();
+ option::deletePrefResource();
return true;
}
diff --git a/src/prefs.cc b/src/prefs.cc
index 6675de2e..62089096 100644
--- a/src/prefs.cc
+++ b/src/prefs.cc
@@ -51,6 +51,13 @@ public:
// We add special null pref whose ID is 0.
makePref("");
}
+ ~PrefFactory()
+ {
+ for(size_t i = 0; i < count_; ++i) {
+ delete i2p_[i];
+ }
+ }
+
size_t nextId()
{
return count_++;
@@ -117,6 +124,11 @@ const Pref* k2p(const std::string& key)
return getPrefFactory()->k2p(key);
}
+void deletePrefResource()
+{
+ delete getPrefFactory();
+}
+
} // namespace option
/**
diff --git a/src/prefs.h b/src/prefs.h
index 01ed3397..ec15169c 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -60,6 +60,10 @@ const Pref* i2p(size_t id);
// special null Pref whose ID is 0.
const Pref* k2p(const std::string& k);
+// Deletes resources allocated for preferences. Call this function at
+// the end of the program only once.
+void deletePrefResource();
+
} // namespace option
/**