From cea97e5cc63dd99804714903fed94e925cc7475a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 1 Jan 2019 19:40:57 +0100 Subject: [PATCH] - fixed memory leaks in network code. ReadString allocates a buffer, so saving it in a local variable and then forgetting it will not free the buffer afterward. (This should probably be refactored to use some safer methods to read the string than this old-school method...) --- src/d_net.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/d_net.cpp b/src/d_net.cpp index d97050d48..3f911ed64 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2487,10 +2487,10 @@ void Net_DoCommand (int type, uint8_t **stream, int player) case DEM_RUNNAMEDSCRIPT: { - char *sname = ReadString(stream); + s = ReadString(stream); int argn = ReadByte(stream); - RunScript(stream, players[player].mo, -FName(sname), argn & 127, (argn & 128) ? ACS_ALWAYS : 0); + RunScript(stream, players[player].mo, -FName(s), argn & 127, (argn & 128) ? ACS_ALWAYS : 0); } break; @@ -2557,9 +2557,9 @@ void Net_DoCommand (int type, uint8_t **stream, int player) case DEM_KILLCLASSCHEAT: { - char *classname = ReadString (stream); + s = ReadString (stream); int killcount = 0; - PClassActor *cls = PClass::FindActor(classname); + PClassActor *cls = PClass::FindActor(s); if (cls != NULL) { @@ -2569,20 +2569,20 @@ void Net_DoCommand (int type, uint8_t **stream, int player) { killcount += KillAll(cls_rep); } - Printf ("Killed %d monsters of type %s.\n",killcount, classname); + Printf ("Killed %d monsters of type %s.\n",killcount, s); } else { - Printf ("%s is not an actor class.\n", classname); + Printf ("%s is not an actor class.\n", s); } } break; case DEM_REMOVE: { - char *classname = ReadString(stream); + s = ReadString(stream); int removecount = 0; - PClassActor *cls = PClass::FindActor(classname); + PClassActor *cls = PClass::FindActor(s); if (cls != NULL && cls->IsDescendantOf(RUNTIME_CLASS(AActor))) { removecount = RemoveClass(cls); @@ -2591,11 +2591,11 @@ void Net_DoCommand (int type, uint8_t **stream, int player) { removecount += RemoveClass(cls_rep); } - Printf("Removed %d actors of type %s.\n", removecount, classname); + Printf("Removed %d actors of type %s.\n", removecount, s); } else { - Printf("%s is not an actor class.\n", classname); + Printf("%s is not an actor class.\n", s); } } break;