From d9cb0702158fd045285f2c0a904cb31a45a3864a Mon Sep 17 00:00:00 2001 From: Anubisss Date: Sat, 23 Jan 2010 14:45:58 +0100 Subject: 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 --- src/game/Item.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'src/game/Item.cpp') diff --git a/src/game/Item.cpp b/src/game/Item.cpp index 7d6e1cd3021..1a32bfd4107 100644 --- a/src/game/Item.cpp +++ b/src/game/Item.cpp @@ -339,18 +339,14 @@ void Item::SaveToDB() SetState(ITEM_UNCHANGED); } -bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result) +bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result) { // create item before any checks for store correct guid // and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB Object::_Create(guid, 0, HIGHGUID_ITEM); - bool delete_result = false; if(!result) - { result = CharacterDatabase.PQuery("SELECT data FROM item_instance WHERE guid = '%u'", guid); - delete_result = true; - } if (!result) { @@ -363,7 +359,6 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result) if(!LoadValues(fields[0].GetString())) { sLog.outError("Item #%d have broken data in `data` field. Can't be loaded.",guid); - if (delete_result) delete result; return false; } @@ -377,8 +372,6 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result) need_save = true; } - if (delete_result) delete result; - ItemPrototype const* proto = GetProto(); if(!proto) return false; -- cgit v1.2.3