mirror of https://github.com/aria2/aria2
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.pull/36/head
parent
a8641b0998
commit
9d7bb9d01a
|
@ -347,4 +347,9 @@ const SharedHandle<OptionParser>& OptionParser::getInstance()
|
||||||
return optionParser_;
|
return optionParser_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptionParser::deleteInstance()
|
||||||
|
{
|
||||||
|
optionParser_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -94,6 +94,9 @@ public:
|
||||||
const OptionHandler* findByShortName(char shortName) const;
|
const OptionHandler* findByShortName(char shortName) const;
|
||||||
|
|
||||||
static const SharedHandle<OptionParser>& getInstance();
|
static const SharedHandle<OptionParser>& getInstance();
|
||||||
|
// Deletes statically allocated instace. Call this at the end of the
|
||||||
|
// program.
|
||||||
|
static void deleteInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -73,6 +73,8 @@
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
|
#include "OptionParser.h"
|
||||||
|
#include "prefs.h"
|
||||||
#ifdef HAVE_LIBGMP
|
#ifdef HAVE_LIBGMP
|
||||||
# include "a2gmp.h"
|
# include "a2gmp.h"
|
||||||
#endif // HAVE_LIBGMP
|
#endif // HAVE_LIBGMP
|
||||||
|
@ -172,7 +174,11 @@ bool Platform::tearDown()
|
||||||
#ifdef HAVE_WINSOCK2_H
|
#ifdef HAVE_WINSOCK2_H
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
#endif // HAVE_WINSOCK2_H
|
#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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/prefs.cc
12
src/prefs.cc
|
@ -51,6 +51,13 @@ public:
|
||||||
// We add special null pref whose ID is 0.
|
// We add special null pref whose ID is 0.
|
||||||
makePref("");
|
makePref("");
|
||||||
}
|
}
|
||||||
|
~PrefFactory()
|
||||||
|
{
|
||||||
|
for(size_t i = 0; i < count_; ++i) {
|
||||||
|
delete i2p_[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t nextId()
|
size_t nextId()
|
||||||
{
|
{
|
||||||
return count_++;
|
return count_++;
|
||||||
|
@ -117,6 +124,11 @@ const Pref* k2p(const std::string& key)
|
||||||
return getPrefFactory()->k2p(key);
|
return getPrefFactory()->k2p(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deletePrefResource()
|
||||||
|
{
|
||||||
|
delete getPrefFactory();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace option
|
} // namespace option
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -60,6 +60,10 @@ const Pref* i2p(size_t id);
|
||||||
// special null Pref whose ID is 0.
|
// special null Pref whose ID is 0.
|
||||||
const Pref* k2p(const std::string& k);
|
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
|
} // namespace option
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue