mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-09-25 22:10:41 -04:00
[Server] Fix memory leak in GetCellStateDescription()
This commit is contained in:
parent
268a1501ad
commit
1c810ecad5
@ -16,7 +16,7 @@ unsigned int CellFunctions::GetCellStateChangesSize(unsigned short pid) noexcept
|
|||||||
return player->cellStateChanges.count;
|
return player->cellStateChanges.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *CellFunctions::GetCellStateDescription(unsigned short pid, unsigned int i) noexcept
|
const char *CellFunctions::GetCellStateDescription(unsigned short pid, unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, "");
|
GET_PLAYER(pid, player, "");
|
||||||
@ -24,12 +24,13 @@ char *CellFunctions::GetCellStateDescription(unsigned short pid, unsigned int i)
|
|||||||
if (i >= player->cellStateChanges.count)
|
if (i >= player->cellStateChanges.count)
|
||||||
return "invalid";
|
return "invalid";
|
||||||
|
|
||||||
std::string cellDescription = player->cellStateChanges.cells.at(i).getDescription();
|
string cellDescription = player->cellStateChanges.cells.at(i).getDescription();
|
||||||
|
|
||||||
char *cstrDescription = new char[cellDescription.length() + 1];
|
static vector<char> cstrDescription;
|
||||||
std::strcpy(cstrDescription, cellDescription.c_str());
|
cstrDescription.reserve(cellDescription.size());
|
||||||
|
strncpy(&cstrDescription[0], cellDescription.c_str(), cstrDescription.capacity());
|
||||||
|
|
||||||
return cstrDescription;
|
return &cstrDescription[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CellFunctions::GetCell(unsigned short pid) noexcept
|
const char *CellFunctions::GetCell(unsigned short pid) noexcept
|
||||||
|
@ -23,7 +23,7 @@ class CellFunctions
|
|||||||
public:
|
public:
|
||||||
static unsigned int GetCellStateChangesSize(unsigned short pid) noexcept;
|
static unsigned int GetCellStateChangesSize(unsigned short pid) noexcept;
|
||||||
|
|
||||||
static char *GetCellStateDescription(unsigned short pid, unsigned int i) noexcept;
|
static const char *GetCellStateDescription(unsigned short pid, unsigned int i) noexcept;
|
||||||
|
|
||||||
static const char *GetCell(unsigned short pid) noexcept;
|
static const char *GetCell(unsigned short pid) noexcept;
|
||||||
static void SetCell(unsigned short pid, const char *name) noexcept;
|
static void SetCell(unsigned short pid, const char *name) noexcept;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user