修复内存泄露问题
This commit is contained in:
parent
5a8bad333e
commit
c902e2833d
@ -18,7 +18,7 @@ endif()
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-std=gnu++11 -fsanitize=address -fno-omit-frame-pointer")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DMASTER_MODE=${MASTER_MODE}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DMASTER_MODE=${MASTER_MODE} -DA8_TCP_SESSION2=1")
|
||||
|
||||
include_directories(
|
||||
AFTER
|
||||
|
@ -71,7 +71,7 @@ static void SavePerfLog()
|
||||
#endif
|
||||
}
|
||||
|
||||
void App::Init(int argc, char* argv[])
|
||||
bool App::Init(int argc, char* argv[])
|
||||
{
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
this->argc = argc;
|
||||
@ -79,10 +79,10 @@ void App::Init(int argc, char* argv[])
|
||||
|
||||
if (!ParseOpt()) {
|
||||
terminated = true;
|
||||
a8::XPrintf("masterserver启动失败,缺少-i参数\n", {});
|
||||
return;
|
||||
a8::XPrintf("wsproxy启动失败,缺少-i参数\n", {});
|
||||
return false;
|
||||
}
|
||||
a8::XPrintf("masterserver starting instance_id:%d pid:%d\n", {instance_id, getpid()});
|
||||
a8::XPrintf("wsproxy starting instance_id:%d pid:%d\n", {instance_id, getpid()});
|
||||
|
||||
loop_mutex_ = new std::mutex();
|
||||
loop_cond_ = new std::condition_variable();
|
||||
@ -100,7 +100,7 @@ void App::Init(int argc, char* argv[])
|
||||
MasterSvrMgr::Instance()->Init();
|
||||
TargetConnMgr::Instance()->Init();
|
||||
|
||||
a8::UdpLog::Instance()->Info("masterserver starting instance_id:%d pid:%d", {instance_id, getpid()});
|
||||
a8::UdpLog::Instance()->Info("wsproxy starting instance_id:%d pid:%d", {instance_id, getpid()});
|
||||
{
|
||||
int perf_log_time = 1000 * 60 * 5;
|
||||
if (getenv("is_dev_env")) {
|
||||
@ -113,13 +113,23 @@ void App::Init(int argc, char* argv[])
|
||||
SavePerfLog();
|
||||
});
|
||||
}
|
||||
if (HasFlag(1)) {
|
||||
a8::Timer::Instance()->AddDeadLineTimer(
|
||||
1000 * 10,
|
||||
a8::XParams(),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
App::Instance()->terminated = true;
|
||||
App::Instance()->NotifyLoopCond();
|
||||
}
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void App::UnInit()
|
||||
{
|
||||
if (terminated) {
|
||||
return;
|
||||
}
|
||||
a8::XPrintf("wsproxy terminating instance_id:%d pid:%d\n", {instance_id, getpid()});
|
||||
MasterSvrMgr::Instance()->UnInit();
|
||||
TargetConnMgr::Instance()->UnInit();
|
||||
GameClientMgr::Instance()->UnInit();
|
||||
@ -129,6 +139,8 @@ void App::UnInit()
|
||||
HandlerMgr::Instance()->UnInit();
|
||||
UnInitLog();
|
||||
|
||||
FreeSocketMsgQueue();
|
||||
FreeIMMsgQueue();
|
||||
delete im_msg_mutex_;
|
||||
im_msg_mutex_ = nullptr;
|
||||
delete msg_mutex_;
|
||||
@ -137,15 +149,13 @@ void App::UnInit()
|
||||
loop_cond_ = nullptr;
|
||||
delete loop_mutex_;
|
||||
loop_mutex_ = nullptr;
|
||||
a8::XPrintf("wsproxy terminated instance_id:%d pid:%d\n", {instance_id, getpid()});
|
||||
}
|
||||
|
||||
int App::Run()
|
||||
{
|
||||
if (terminated) {
|
||||
return 0;
|
||||
}
|
||||
int ret = 0;
|
||||
a8::UdpLog::Instance()->Info("masterserver running", {});
|
||||
a8::UdpLog::Instance()->Info("wsproxy running", {});
|
||||
while (!terminated) {
|
||||
a8::tick_t begin_tick = a8::XGetTickCount();
|
||||
QuickExecute();
|
||||
@ -476,13 +486,22 @@ void App::UnInitLog()
|
||||
bool App::ParseOpt()
|
||||
{
|
||||
int ch = 0;
|
||||
while ((ch = getopt(argc, argv, "i:")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "i:f:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'i':
|
||||
{
|
||||
instance_id = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
{
|
||||
std::vector<std::string> strings;
|
||||
a8::Split(optarg, strings, ',');
|
||||
for (auto& str : strings) {
|
||||
flags.insert(a8::XValue(str).GetInt());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return instance_id > 0;
|
||||
@ -504,3 +523,58 @@ a8::XParams* App::GetContext(long long context_id)
|
||||
auto itr = context_hash_.find(context_id);
|
||||
return itr != context_hash_.end() ? &(itr->second) : nullptr;
|
||||
}
|
||||
|
||||
bool App::HasFlag(int flag)
|
||||
{
|
||||
return flags.find(flag) != flags.end();
|
||||
}
|
||||
|
||||
void App::FreeSocketMsgQueue()
|
||||
{
|
||||
msg_mutex_->lock();
|
||||
if (!work_node_) {
|
||||
work_node_ = top_node_;
|
||||
top_node_ = nullptr;
|
||||
bot_node_ = nullptr;
|
||||
}
|
||||
while (work_node_) {
|
||||
MsgNode* pdelnode = work_node_;
|
||||
work_node_ = work_node_->next;
|
||||
if (pdelnode->buf) {
|
||||
free(pdelnode->buf);
|
||||
}
|
||||
free(pdelnode);
|
||||
if (!work_node_) {
|
||||
work_node_ = top_node_;
|
||||
top_node_ = nullptr;
|
||||
bot_node_ = nullptr;
|
||||
}
|
||||
}
|
||||
msg_mutex_->unlock();
|
||||
}
|
||||
|
||||
void App::FreeIMMsgQueue()
|
||||
{
|
||||
im_msg_mutex_->lock();
|
||||
if (!im_work_node_) {
|
||||
im_work_node_ = im_top_node_;
|
||||
im_top_node_ = nullptr;
|
||||
im_bot_node_ = nullptr;
|
||||
}
|
||||
while (im_work_node_) {
|
||||
IMMsgNode* pdelnode = im_work_node_;
|
||||
im_work_node_ = im_work_node_->next;
|
||||
if (pdelnode->msgid == f8::IM_SysMsgQueue) {
|
||||
a8::XParams* param = (a8::XParams*)pdelnode->params.param1.GetUserData();
|
||||
delete param;
|
||||
}
|
||||
delete pdelnode;
|
||||
if (!im_work_node_) {
|
||||
im_work_node_ = im_top_node_;
|
||||
im_top_node_ = nullptr;
|
||||
im_bot_node_ = nullptr;
|
||||
}
|
||||
}
|
||||
im_msg_mutex_->unlock();
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ class App : public a8::Singleton<App>
|
||||
|
||||
public:
|
||||
|
||||
void Init(int argc, char* argv[]);
|
||||
bool Init(int argc, char* argv[]);
|
||||
void UnInit();
|
||||
|
||||
int Run();
|
||||
@ -31,6 +31,7 @@ class App : public a8::Singleton<App>
|
||||
a8::XParams* AddContext(long long context_id);
|
||||
void DelContext(long long context_id);
|
||||
a8::XParams* GetContext(long long context_id);
|
||||
bool HasFlag(int flag);
|
||||
|
||||
private:
|
||||
void QuickExecute();
|
||||
@ -49,11 +50,14 @@ private:
|
||||
void UnInitLog();
|
||||
|
||||
bool ParseOpt();
|
||||
void FreeSocketMsgQueue();
|
||||
void FreeIMMsgQueue();
|
||||
|
||||
public:
|
||||
int argc = 0;
|
||||
char** argv = nullptr;
|
||||
volatile bool terminated = false;
|
||||
std::set<int> flags;
|
||||
PerfMonitor perf;
|
||||
a8::uuid::SnowFlake uuid;
|
||||
|
||||
|
@ -14,6 +14,10 @@ void GameClientMgr::Init()
|
||||
|
||||
void GameClientMgr::UnInit()
|
||||
{
|
||||
for (auto& pair : socket_hash_) {
|
||||
delete pair.second;
|
||||
}
|
||||
socket_hash_.clear();
|
||||
}
|
||||
|
||||
void GameClientMgr::OnClientDisconnect(a8::XParams& param)
|
||||
|
@ -4,8 +4,9 @@
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int exitcode = 0;
|
||||
App::Instance()->Init(argc, argv);
|
||||
exitcode = App::Instance()->Run();
|
||||
App::Instance()->UnInit();
|
||||
if (App::Instance()->Init(argc, argv)) {
|
||||
exitcode = App::Instance()->Run();
|
||||
App::Instance()->UnInit();
|
||||
}
|
||||
return exitcode;
|
||||
}
|
||||
|
@ -94,6 +94,7 @@ void TargetConn::SendStockMsg()
|
||||
void TargetConn::ForwardClientMsg(f8::MsgHdr& hdr)
|
||||
{
|
||||
char* buff = (char*)malloc(sizeof(f8::WSProxyPackHead_C) + hdr.buflen);
|
||||
memset(buff, 0, sizeof(f8::WSProxyPackHead_C));
|
||||
f8::WSProxyPackHead_C* head = (f8::WSProxyPackHead_C*)buff;
|
||||
head->packlen = hdr.buflen;
|
||||
head->msgid = hdr.msgid;
|
||||
|
@ -26,6 +26,10 @@ void TargetConnMgr::Init()
|
||||
|
||||
void TargetConnMgr::UnInit()
|
||||
{
|
||||
for (auto& pair : id_hash_) {
|
||||
pair.second->UnInit();
|
||||
delete pair.second;
|
||||
}
|
||||
}
|
||||
|
||||
TargetConn* TargetConnMgr::GetConnByKey(const std::string& key)
|
||||
|
2
third_party/a8engine
vendored
2
third_party/a8engine
vendored
@ -1 +1 @@
|
||||
Subproject commit 07650796618d3d5f86bc3749e817bdc4848458b9
|
||||
Subproject commit 0ae4192e3a75e5627a80e5131fb4425948f146b6
|
2
third_party/framework
vendored
2
third_party/framework
vendored
@ -1 +1 @@
|
||||
Subproject commit 0d1fd33446c6dda16e8ecb5a0ad9b0e42c44deee
|
||||
Subproject commit 7af5d3b84aeaa84a2979c24db9db5ed5a43cea2d
|
Loading…
x
Reference in New Issue
Block a user