Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

Reply
 
Thread Tools Display Modes
  #1  
Old 07-28-2003, 06:25 AM
Deawin
Fire Beetle
 
Join Date: Jun 2003
Location: Vienna, Austria
Posts: 11
Default Fix crash in Database::GetSharedBank

Code:
void Database::GetSharedBank(int32 account_id,Shared_Bank_Struct* sharedbank){
	char errbuf[MYSQL_ERRMSG_SIZE];
    char *query = 0;
    MYSQL_RES *result;
    MYSQL_ROW row;
	unsigned long* lengths;
	if (RunQuery(query, MakeAnyLenString(&query, "SELECT sharedbank from account WHERE id=%i", account_id), errbuf, &result)) {
		safe_delete_array(query);
		if (mysql_num_rows(result) == 1) {	
			row = mysql_fetch_row(result);
			lengths = mysql_fetch_lengths(result);
			if (lengths[0] == sizeof(Shared_Bank_Struct)) {
				memcpy(sharedbank, row[0], sizeof(Shared_Bank_Struct));
				mysql_free_result(result);
				return;
			}
			else{
				cerr << "Length error in GetSharedBank.  Expected: " << sizeof(Shared_Bank_Struct) << ", Got: " << lengths[0] << endl;
				mysql_free_result(result);
				return;
			}


		}
	}
	else
	{
		cerr << "Err in Database::GetSharedBank(int32 account_id): " << errbuf << endl;
		mysql_free_result(result);   // <- HERE
	}
}

At the very end of this function, mysql_free_result(result) should not be called if RunQuery() returned false.
This crashed on my machine because my DB layout was a little wrong but could crash on other occasions as well.

Maybe DBcore::RunQuery should set *result to NULL at the beginning of the function so that you can check if it needs to be freed in the code elsewhere (like above):
Code:
if(result) mysql_free_result(result);
or build a macro around it, or whatever.

Hope that helps and please to ignore if I am totally wrong :P
Markus
Reply With Quote
  #2  
Old 07-28-2003, 07:56 AM
Edgar1898
Senior Member
Former EQEmu Developer
Current EQ2Emu Lead Developer
 
Join Date: Dec 2002
Posts: 1,065
Default

K Thanks, Ill fix it
I wasnt aware there was a bug with my function :P
__________________
Lethal Encounter
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 03:17 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3