Implement QueryResult_AutoPtr type which is ACE's reference counted auto_ptr(ACE_Refcounted_Auto_Ptr) for QueryResult pointers.

Use this auto_ptr for every DB queries(except QueryNamedResult yet).

This patch guarantees NO memory leaks from QueryResult pointers.

Thanks to raczman for the idea and for the helping to make this patch.

--HG--
branch : trunk
This commit is contained in:
Anubisss
2010-01-23 14:45:58 +01:00
parent c784110d87
commit d9cb070215
76 changed files with 458 additions and 1108 deletions

View File

@@ -109,7 +109,7 @@ bool SqlQueryHolder::SetQuery(size_t index, const char *sql)
}
/// not executed yet, just stored (it's not called a holder for nothing)
m_queries[index] = SqlResultPair(strdup(sql), NULL);
m_queries[index] = SqlResultPair(strdup(sql), QueryResult_AutoPtr(NULL));
return true;
}
@@ -136,7 +136,7 @@ bool SqlQueryHolder::SetPQuery(size_t index, const char *format, ...)
return SetQuery(index,szQuery);
}
QueryResult* SqlQueryHolder::GetResult(size_t index)
QueryResult_AutoPtr SqlQueryHolder::GetResult(size_t index)
{
if(index < m_queries.size())
{
@@ -150,10 +150,10 @@ QueryResult* SqlQueryHolder::GetResult(size_t index)
return m_queries[index].second;
}
else
return NULL;
return QueryResult_AutoPtr(NULL);
}
void SqlQueryHolder::SetResult(size_t index, QueryResult *result)
void SqlQueryHolder::SetResult(size_t index, QueryResult_AutoPtr result)
{
/// store the result in the holder
if(index < m_queries.size())
@@ -167,11 +167,7 @@ SqlQueryHolder::~SqlQueryHolder()
/// if the result was never used, free the resources
/// results used already (getresult called) are expected to be deleted
if(m_queries[i].first != NULL)
{
free((void*)(const_cast<char*>(m_queries[i].first)));
if(m_queries[i].second)
delete m_queries[i].second;
}
}
}