Fix for Ruby-rand memory leak

- Also prefixes the "mt" member variable with a "m_"
This commit is contained in:
AltF4 committed 2014-08-13 17:02:15 -07:00
1 parent c2b0cf86a9
commit b03a4847ce
2 files changed
+12 -7

No files matched your search

+11 -6
View File
@@ -10,11 +10,15 @@
Ruby::Ruby()
{
seedValue = 0;
mt = new MT;
init_genrand(mt, seedValue);
m_mt = new MT;
init_genrand(m_mt, seedValue);
}
Ruby::~Ruby() {}
Ruby::~Ruby()
{
delete m_mt;
m_mt = NULL;
}
const std::string Ruby::getName()
{
@@ -23,9 +27,10 @@ const std::string Ruby::getName()
void Ruby::seed(uint32_t value)
{
mt = new MT;
delete m_mt;
m_mt = new MT;
seedValue = value;
init_genrand(mt, value);
init_genrand(m_mt, value);
}
uint32_t Ruby::getSeed()
@@ -35,7 +40,7 @@ uint32_t Ruby::getSeed()
uint32_t Ruby::random()
{
return genrand_int32(mt);
return genrand_int32(m_mt);
}
+1 -1
View File
@@ -61,7 +61,7 @@ private:
void next_state(struct MT *mt);
uint32_t genrand_int32(struct MT *mt);
MT *mt;
MT *m_mt;
uint32_t seedValue;
};