View Single Post
  #4  
Old 11-20-2003, 02:38 AM
Trumpcard
Demi-God
 
Join Date: Jan 2002
Location: Charlotte, NC
Posts: 2,614
Default

Theres one too fix..


Code:
if (RunQuery(query, MakeAnyLenString(&query, "SELECT loottable_id, lootdrop_id, multiplier, probability FROM loottable_entries WHERE loottable_id=%i", tmpid), errbuf, &result2)) {
				safe_delete_array(query);
				tmpLT = (LootTable_Struct*) new uchar[sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * mysql_num_rows(result2))];
				memset(tmpLT, 0, sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * mysql_num_rows(result2)));
				tmpLT->NumEntries = mysql_num_rows(result2);
				tmpLT->mincash = tmpmincash;
				tmpLT->maxcash = tmpmaxcash;
				tmpLT->avgcoin = tmpavgcoin;
				i=0;
				while ((row = mysql_fetch_row(result2))) {
					if (i >= tmpLT->NumEntries) {
						mysql_free_result(result);
						mysql_free_result(result2);
						cerr << "Error in Database::DBLoadLoot, i >= NumEntries" << endl;
						return false;
					}
					tmpLT->Entries[i].lootdrop_id = atoi(row[1]);
					tmpLT->Entries[i].multiplier = atoi(row[2]);
					tmpLT->Entries[i].probability = atoi(row[3]);
					i++;
				}
				if (!EMuShareMemDLL.Loot.cbAddLootTable(tmpid, tmpLT)) {
					mysql_free_result(result);
					mysql_free_result(result2);
					safe_delete(tmpLT);
					cout << "Error in Database::DBLoadLoot: !cbAddLootTable(" << tmpid << ")" << endl;
					return false;
				}
				safe_delete(tmpLT);
				mysql_free_result(result2);
The problem is here..

tmpLT = (LootTable_Struct*) new uchar[sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * mysql_num_rows(result2))];

and its dealloc'd with

safe_delete(tmpLT);


That delete should be a safe_delete_array since it's new'd as uchar[x]



The one in seperator confuses me.. This is the deconstructor

91 ~Seperator() {
92 for (int i=0; i<=maxargnum; i++)
93 safe_delete(arg[i]);
94 safe_delete_array(arg);
95 safe_delete_array(argplus);
96 }


If you have an array of new'd objects, do you need to delete each member of the array, do you need to dealloc each member of the array, and then the array itself ?
__________________
Quitters never win, and winners never quit, but those who never win and never quit are idiots.
Reply With Quote