Skip to content

Commit

Permalink
Fix minor memory leak on loading/unloading transporters.
Browse files Browse the repository at this point in the history
DROID::sMove.asPath is set to NULL on unloading droids, but was never freed.

Also, clear any remaining pathfinding job for the droid on loading transporter.
  • Loading branch information
Cyp committed Jun 23, 2012
1 parent 88e9439 commit 032956e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/droid.cpp
Expand Up @@ -1898,6 +1898,7 @@ DROID *reallyBuildDroid(DROID_TEMPLATE *pTemplate, Position pos, UDWORD player,
// Initialise the movement stuff
psDroid->baseSpeed = calcDroidBaseSpeed(pTemplate, psDroid->weight, (UBYTE)player);

psDroid->sMove.asPath = NULL;
initDroidMovement(psDroid);

// it was never drawn before
Expand Down Expand Up @@ -1988,6 +1989,7 @@ DROID *buildDroid(DROID_TEMPLATE *pTemplate, UDWORD x, UDWORD y, UDWORD player,
//initialises the droid movement model
void initDroidMovement(DROID *psDroid)
{
free(psDroid->sMove.asPath);
memset(&psDroid->sMove, 0, sizeof(MOVE_CONTROL));
}

Expand Down
1 change: 1 addition & 0 deletions src/transporter.cpp
Expand Up @@ -1437,6 +1437,7 @@ void transporterAddDroid(DROID *psTransporter, DROID *psDroidToAdd)
{
visRemoveVisibility((BASE_OBJECT *)psDroidToAdd);
}
fpathRemoveDroidData(psDroidToAdd->id);

// This is called by droidRemove. But we still need to refresh after adding to the transporter group.
intRefreshScreen();
Expand Down

0 comments on commit 032956e

Please sign in to comment.