X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..67362c8e2e2d6d9f666176d3479b45259522d27b:/projects/stargazer/traffcounter.cpp?ds=sidebyside diff --git a/projects/stargazer/traffcounter.cpp b/projects/stargazer/traffcounter.cpp index 54014167..1d088f48 100644 --- a/projects/stargazer/traffcounter.cpp +++ b/projects/stargazer/traffcounter.cpp @@ -30,6 +30,7 @@ #include #include +#include // Functions fopen and similar #include "traffcounter.h" #include "common.h" @@ -287,7 +288,7 @@ int oldIp2packetsSize = ip2packets.size(); pp_iter pi; pi = packets.begin(); std::map newPackets; -std::multimap newIP2Packets; +ip2packets.erase(ip2packets.begin(), ip2packets.end()); while (pi != packets.end()) { //Flushing @@ -388,14 +389,13 @@ while (pi != packets.end()) pair res = newPackets.insert(*pi); if (res.second) { - newIP2Packets.insert(make_pair(pi->first.GetSrcIP(), res.first)); - newIP2Packets.insert(make_pair(pi->first.GetDstIP(), res.first)); + ip2packets.insert(make_pair(pi->first.GetSrcIP(), res.first)); + ip2packets.insert(make_pair(pi->first.GetDstIP(), res.first)); } } ++pi; } swap(packets, newPackets); -swap(ip2packets, newIP2Packets); printfd(__FILE__, "FlushAndRemove() packets: %d(rem %d) ip2packets: %d(rem %d)\n", packets.size(), oldPacketsSize - packets.size(), @@ -410,7 +410,7 @@ printfd(__FILE__, "AddUser: %s\n", user->GetLogin().c_str()); uint32_t uip = user->GetCurrIP(); pair pi; -STG_LOCKER(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex, __FILE__, __LINE__); // Find all packets with IP belongs to this user pi = ip2packets.equal_range(uip); @@ -447,7 +447,7 @@ void TRAFFCOUNTER::DelUser(uint32_t uip) printfd(__FILE__, "DelUser: %s \n", inet_ntostring(uip).c_str()); pair pi; -STG_LOCKER(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex, __FILE__, __LINE__); pi = ip2packets.equal_range(uip); while (pi.first != pi.second) @@ -699,6 +699,7 @@ while (fgets(str, 1023, f)) if (r != 3) { WriteServLog("Error in file %s. There must be 3 parameters. Line %d.", rulesFileName.c_str(), lineNumber); + fclose(f); return true; } @@ -721,6 +722,7 @@ while (fgets(str, 1023, f)) { WriteServLog("Error in file %s. Line %d.", rulesFileName.c_str(), lineNumber); + fclose(f); return true; } @@ -728,6 +730,7 @@ while (fgets(str, 1023, f)) { WriteServLog("Error in file %s. Error in adress. Line %d.", rulesFileName.c_str(), lineNumber); + fclose(f); return true; } if (!test)