mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 07:37:01 +00:00
[8736] operator new[] based version of strdup() function to get bonuses from Intel Memory allocator mainly in DB code
Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
parent
a2ed351365
commit
b0ea8848a5
7 changed files with 29 additions and 19 deletions
|
|
@ -768,7 +768,7 @@ void ChatHandler::SendSysMessage(const char *str)
|
||||||
WorldPacket data;
|
WorldPacket data;
|
||||||
|
|
||||||
// need copy to prevent corruption by strtok call in LineFromMessage original string
|
// need copy to prevent corruption by strtok call in LineFromMessage original string
|
||||||
char* buf = strdup(str);
|
char* buf = mangos_strdup(str);
|
||||||
char* pos = buf;
|
char* pos = buf;
|
||||||
|
|
||||||
while(char* line = LineFromMessage(pos))
|
while(char* line = LineFromMessage(pos))
|
||||||
|
|
@ -777,7 +777,7 @@ void ChatHandler::SendSysMessage(const char *str)
|
||||||
m_session->SendPacket(&data);
|
m_session->SendPacket(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
delete [] buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatHandler::SendGlobalSysMessage(const char *str)
|
void ChatHandler::SendGlobalSysMessage(const char *str)
|
||||||
|
|
@ -786,7 +786,7 @@ void ChatHandler::SendGlobalSysMessage(const char *str)
|
||||||
WorldPacket data;
|
WorldPacket data;
|
||||||
|
|
||||||
// need copy to prevent corruption by strtok call in LineFromMessage original string
|
// need copy to prevent corruption by strtok call in LineFromMessage original string
|
||||||
char* buf = strdup(str);
|
char* buf = mangos_strdup(str);
|
||||||
char* pos = buf;
|
char* pos = buf;
|
||||||
|
|
||||||
while(char* line = LineFromMessage(pos))
|
while(char* line = LineFromMessage(pos))
|
||||||
|
|
@ -795,7 +795,7 @@ void ChatHandler::SendGlobalSysMessage(const char *str)
|
||||||
sWorld.SendGlobalMessage(&data);
|
sWorld.SendGlobalMessage(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
delete [] buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatHandler::SendSysMessage(int32 entry)
|
void ChatHandler::SendSysMessage(int32 entry)
|
||||||
|
|
|
||||||
|
|
@ -1769,7 +1769,7 @@ void World::SendGlobalText(const char* text, WorldSession *self)
|
||||||
WorldPacket data;
|
WorldPacket data;
|
||||||
|
|
||||||
// need copy to prevent corruption by strtok call in LineFromMessage original string
|
// need copy to prevent corruption by strtok call in LineFromMessage original string
|
||||||
char* buf = strdup(text);
|
char* buf = mangos_strdup(text);
|
||||||
char* pos = buf;
|
char* pos = buf;
|
||||||
|
|
||||||
while(char* line = ChatHandler::LineFromMessage(pos))
|
while(char* line = ChatHandler::LineFromMessage(pos))
|
||||||
|
|
@ -1778,7 +1778,7 @@ void World::SendGlobalText(const char* text, WorldSession *self)
|
||||||
SendGlobalMessage(&data, self);
|
SendGlobalMessage(&data, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
delete [] buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a packet to all players (or players selected team) in the zone (except self if mentioned)
|
/// Send a packet to all players (or players selected team) in the zone (except self if mentioned)
|
||||||
|
|
|
||||||
|
|
@ -242,7 +242,7 @@ void RASocket::zprint( const char * szText )
|
||||||
|
|
||||||
#ifdef RA_CRYPT
|
#ifdef RA_CRYPT
|
||||||
|
|
||||||
char *megabuffer=strdup(szText);
|
char *megabuffer = mangos_strdup(szText);
|
||||||
unsigned int sz=strlen(megabuffer);
|
unsigned int sz=strlen(megabuffer);
|
||||||
Encrypt(megabuffer,sz);
|
Encrypt(megabuffer,sz);
|
||||||
send(r,megabuffer,sz,0);
|
send(r,megabuffer,sz,0);
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,16 @@ enum LocaleConstant
|
||||||
extern char const* localeNames[MAX_LOCALE];
|
extern char const* localeNames[MAX_LOCALE];
|
||||||
|
|
||||||
LocaleConstant GetLocaleByName(const std::string& name);
|
LocaleConstant GetLocaleByName(const std::string& name);
|
||||||
|
//operator new[] based version of strdup() function! Release memory by using operator delete[] !
|
||||||
|
inline char * mangos_strdup(const char * source)
|
||||||
|
{
|
||||||
|
const size_t length = strlen(source);
|
||||||
|
char * dest = new char[length + 1];
|
||||||
|
//set terminating end-of-string symbol
|
||||||
|
dest[length] = 0;
|
||||||
|
strcpy(dest, source);
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
// we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some pother platforms)
|
// we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some pother platforms)
|
||||||
#ifdef max
|
#ifdef max
|
||||||
|
|
|
||||||
|
|
@ -41,17 +41,17 @@ void SqlTransaction::Execute(Database *db)
|
||||||
|
|
||||||
if(!db->DirectExecute(sql))
|
if(!db->DirectExecute(sql))
|
||||||
{
|
{
|
||||||
free((void*)const_cast<char*>(sql));
|
delete [] ((void*)const_cast<char*>(sql));
|
||||||
db->DirectExecute("ROLLBACK");
|
db->DirectExecute("ROLLBACK");
|
||||||
while(!m_queue.empty())
|
while(!m_queue.empty())
|
||||||
{
|
{
|
||||||
free((void*)const_cast<char*>(m_queue.front()));
|
delete [] ((void*)const_cast<char*>(m_queue.front()));
|
||||||
m_queue.pop();
|
m_queue.pop();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free((void*)const_cast<char*>(sql));
|
delete [] ((void*)const_cast<char*>(sql));
|
||||||
}
|
}
|
||||||
db->DirectExecute("COMMIT");
|
db->DirectExecute("COMMIT");
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +107,7 @@ bool SqlQueryHolder::SetQuery(size_t index, const char *sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// not executed yet, just stored (it's not called a holder for nothing)
|
/// not executed yet, just stored (it's not called a holder for nothing)
|
||||||
m_queries[index] = SqlResultPair(strdup(sql), (QueryResult*)NULL);
|
m_queries[index] = SqlResultPair(mangos_strdup(sql), (QueryResult*)NULL);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,7 +141,7 @@ QueryResult* SqlQueryHolder::GetResult(size_t index)
|
||||||
/// the query strings are freed on the first GetResult or in the destructor
|
/// the query strings are freed on the first GetResult or in the destructor
|
||||||
if(m_queries[index].first != NULL)
|
if(m_queries[index].first != NULL)
|
||||||
{
|
{
|
||||||
free((void*)(const_cast<char*>(m_queries[index].first)));
|
delete [] ((void*)(const_cast<char*>(m_queries[index].first)));
|
||||||
m_queries[index].first = NULL;
|
m_queries[index].first = NULL;
|
||||||
}
|
}
|
||||||
/// when you get a result aways remember to delete it!
|
/// when you get a result aways remember to delete it!
|
||||||
|
|
@ -166,7 +166,7 @@ SqlQueryHolder::~SqlQueryHolder()
|
||||||
/// results used already (getresult called) are expected to be deleted
|
/// results used already (getresult called) are expected to be deleted
|
||||||
if(m_queries[i].first != NULL)
|
if(m_queries[i].first != NULL)
|
||||||
{
|
{
|
||||||
free((void*)(const_cast<char*>(m_queries[i].first)));
|
delete [] ((void*)(const_cast<char*>(m_queries[i].first)));
|
||||||
if(m_queries[i].second)
|
if(m_queries[i].second)
|
||||||
delete m_queries[i].second;
|
delete m_queries[i].second;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ class SqlStatement : public SqlOperation
|
||||||
private:
|
private:
|
||||||
const char *m_sql;
|
const char *m_sql;
|
||||||
public:
|
public:
|
||||||
SqlStatement(const char *sql) : m_sql(strdup(sql)){}
|
SqlStatement(const char *sql) : m_sql(mangos_strdup(sql)){}
|
||||||
~SqlStatement() { void* tofree = const_cast<char*>(m_sql); free(tofree); }
|
~SqlStatement() { void* tofree = const_cast<char*>(m_sql); delete [] tofree; }
|
||||||
void Execute(Database *db);
|
void Execute(Database *db);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ class SqlTransaction : public SqlOperation
|
||||||
std::queue<const char *> m_queue;
|
std::queue<const char *> m_queue;
|
||||||
public:
|
public:
|
||||||
SqlTransaction() {}
|
SqlTransaction() {}
|
||||||
void DelayExecute(const char *sql) { m_queue.push(strdup(sql)); }
|
void DelayExecute(const char *sql) { m_queue.push(mangos_strdup(sql)); }
|
||||||
void Execute(Database *db);
|
void Execute(Database *db);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -84,8 +84,8 @@ class SqlQuery : public SqlOperation
|
||||||
SqlResultQueue * m_queue;
|
SqlResultQueue * m_queue;
|
||||||
public:
|
public:
|
||||||
SqlQuery(const char *sql, MaNGOS::IQueryCallback * callback, SqlResultQueue * queue)
|
SqlQuery(const char *sql, MaNGOS::IQueryCallback * callback, SqlResultQueue * queue)
|
||||||
: m_sql(strdup(sql)), m_callback(callback), m_queue(queue) {}
|
: m_sql(mangos_strdup(sql)), m_callback(callback), m_queue(queue) {}
|
||||||
~SqlQuery() { void* tofree = const_cast<char*>(m_sql); free(tofree); }
|
~SqlQuery() { void* tofree = const_cast<char*>(m_sql); delete [] tofree; }
|
||||||
void Execute(Database *db);
|
void Execute(Database *db);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "8735"
|
#define REVISION_NR "8736"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue