Issue information

Issue ID
#4969
Status
Fixed
Severity
None
Started
Hercules Elf Bot
Jun 16, 2011 18:54
Last Post
Hercules Elf Bot
Jun 16, 2011 18:54
Confirmation
N/A

Hercules Elf Bot - Jun 16, 2011 18:54

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

When using a DBMap with string keys with DB_OPT_DUP_KEY, everytime a new entry is inserted, a copy of the key string is allocated and stored. Depending on the 'maxlen' parameter (which controls the max. length of the string), the code either runs aStrdup(), or does its own thing:
CODE
            if (db->maxlen) {
                CREATE(str, char, db->maxlen +1);
                strncpy(str, key.str, db->maxlen);
                str[db->maxlen] = '\0';
                key.str = str;
            } else {
                key.str = (char *)aStrdup(key.str);
            }

The problem is that in the first case, it allocates the maximum possible size, no matter what the actual length of the input string is.
A quick test shows that by allocating only the required amount, a default eA setup's memory usage goes down by 400kB.
This is because the offending code is run by npcname_db and scriptlabel_db, major components of the script system.