summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
/**