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 committed 2010-01-23 14:45:58 +01:00
1 parent c784110d87
commit d9cb070215
76 files changed
+458 -1108

No files matched your search

+4 -7
View File
@@ -117,9 +117,9 @@ void Database::SetResultQueue(SqlResultQueue * queue)
}
QueryResult* Database::PQuery(const char *format,...)
QueryResult_AutoPtr Database::PQuery(const char *format,...)
{
if(!format) return NULL;
if(!format) return QueryResult_AutoPtr(NULL);
va_list ap;
char szQuery [MAX_QUERY_LEN];
@@ -130,7 +130,7 @@ QueryResult* Database::PQuery(const char *format,...)
if(res==-1)
{
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
return false;
return QueryResult_AutoPtr(NULL);
}
return Query(szQuery);
@@ -217,12 +217,9 @@ bool Database::DirectPExecute(const char * format,...)
bool Database::CheckRequiredField( char const* table_name, char const* required_name )
{
// check required field
QueryResult* result = PQuery("SELECT %s FROM %s LIMIT 1",required_name,table_name);
QueryResult_AutoPtr result = PQuery("SELECT %s FROM %s LIMIT 1",required_name,table_name);
if(result)
{
delete result;
return true;
}
// check fail, prepare readabale error message