I've spent the past few days with some rather serious memory issues with
the game, while trying to push everything over to an sql database. I've
managed to find out the problem commands, and ALL link back to SQL for
some reason. Has anyone else had a problem with sql commands increasing
the game's memory usage like this?
Here's an example of just one of the commands that are doing this:
void show_hiscore_age (CHAR_DATA *ch)
{
struct database *db=NULL;
MYSQL_RES *result = NULL;
MYSQL_ROW row;
char sql[2 * MSL];
char *username="";
char buf[MSL];
int rank=1;
int rating = 0;
int records;
BUFFER *output;
output = new_buf();
sprintf(buf, "%s Age\n\r", theader2);
add_buf(output,buf);
sprintf(buf, "%s", theader);
add_buf(output,buf);
free_string(buf);
sprintf(sql, "SELECT * FROM stats WHERE immort > \'1\' AND age >'17'
ORDER BY -age LIMIT 0, 10");
db=send_query(sql);
result=db->result;
records = mysql_num_rows(result);
if (records < 1) {
return;
}
if (records > 0) {
for (; records > 0; records--) {
row = mysql_fetch_row(result);
username=str_dup(row[1]);
rating=atoi(row[4]);
sprintf(buf, "{r+ {RRank{x {B[{W%2d{B]{R Name:{C %-16s {BScore: {W
[{Y%9d{W]{r +{x\n\r", rank, username, rating);
add_buf(output, buf);
free_string(buf);
rank++;
}
}
sprintf(buf, "%s", theader);
add_buf(output,buf);
free_string(buf);
free_string(sql);
free(username);
free(db);
page_to_char( buf_string(output), ch );
free_buf(output);
}
and send_query:
struct database *send_query(char *command)
{ char buf[MSL];
struct database *db=NULL;
sigset_t set;
sigaddset(&set, SIGUSR1);
sigaddset(&set, SIGIO);
sigaddset(&set, SIGALRM);
sigaddset(&set, SIGUSR2);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGQUIT);
sigaddset(&set, SIGHUP);
sigaddset(&set, SIGTERM);
sigaddset(&set, SIGABRT);
if(sigprocmask(SIG_BLOCK,&set,NULL)<0)
error_db(0,6);
db = (struct database *) calloc(1, sizeof(struct database ));
if (mysql_query(&my_connection, command))
{
error_db(command,1);
}
if (!(db->result=mysql_store_result(&my_connection)))
{
error_db(command, 2 );
}
db->rows=mysql_num_rows(db->result);
db->fields=mysql_num_fields(db->result);
if (sigprocmask(SIG_UNBLOCK,&set, NULL)<0)
error_db(0,5);
return(db);
}
Everything that I know can be freed IS freed somehow... Am I missing
something? From what I've seen the memory increase is rather small, but
still it IS something that is frustrating and annoying. Thoughts, ideas?
Oh, and while on the SQL topic, for some reason, getting this to WRITE
to a database is a guaranteed crash for the mud, using this very same
persistant connection. It will write just fine, but it's like it's
missing something?
+----------------------------------------------------+
+ TJW: Head Tech, designer: Dreamless Realms Mud +
+ Mud : http://drealms.kyndig.com +
+ Telnet: drealms.kyndig.com port 9275 +
+ OLC Docs: http://olc.kyndig.com +
+----------------------------------------------------+