Issue information

Issue ID
#312
Status
Fixed
Severity
Critical
Started
Hercules Elf Bot
Oct 26, 2007 17:45
Last Post
Hercules Elf Bot
Oct 26, 2007 17:45
Confirmation
N/A

Hercules Elf Bot - Oct 26, 2007 17:45

Originally posted by [b]theultramage[/b]
http://www.eathena.ws/board/index.php?autocom=bugtracker&showbug=312

I found this after noticing that my TXT charserver was periodically throwing send buffer overload errors.
It also explains why sometimes my testserver takes a while to start up (system allocating 500M of RAM and such).

CODE
int send_accounts_tologin(int tid, unsigned int tick, int id, int data)
{
    int users = count_users();
    online_char_db->foreach(online_char_db, send_accounts_tologin_sub, &i);
...
}

static int send_accounts_tologin_sub(DBKey key, void* data, va_list ap)
{
    int *i = va_arg(ap, int*);
    int count = va_arg(ap, int);
    WFIFOHEAD(login_fd,8+count*4);
...
}
Basically what happens is that on TXT, the foreach() call is not sending the 'users' parameter that the called function assumes is sent. Therefore 'count' becomes random junk from memory interpreted as a 4-byte integer, and then used to allocate a dynamic buffer. EACH TIME FOR EACH ONLINE ACCOUNT!!!!!!!!!!!!!!!!!!!!!!!!

A not-very-amusing fact is that this typo has been there since it was implemented in r4763 by Skotlex.
Also, notice that it's enumerating the contents of online_char_db, but is using count_users() to set the packet length. How can anyone be sure that these two will always provide the same value?

By the way, could someone explain what that annoying heap of code is supposed to be for? After a quick look it seems that it's for tracking which accs are online and which aren't, to be able to perform the 'online check'. But shouldn't this thing be handled by the charserver alone? There's no reason to have this mess... is there? Please explain it to me...

CODE
add_timer_interval(gettick() + 3600*1000, send_accounts_tologin, 0, 0, 3600*1000); //Sync online accounts every hour
What is the point of this 'periodic data sync', if all has to go through the login server anyway (thus maintaining sync automatically, meaning this has to be done only once - during connect) ?

This post has been edited by theultramage: Oct 26 2007, 11:15 AM