Skip to content

Commit

Permalink
Fix: Possible dangling pointer in kf_JumpToResourceExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Oct 11, 2023
1 parent 2339507 commit 9d15ce1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/keybind.cpp
Expand Up @@ -1653,6 +1653,14 @@ void kf_JumpToResourceExtractor()

}

void keybindInformResourceExtractorRemoved(const STRUCTURE* psResourceExtractor)
{
if (psOldRE == psResourceExtractor)
{
psOldRE = nullptr;
}
}

// --------------------------------------------------------------------------
MappableFunction kf_JumpToUnits(const DROID_TYPE droidType)
{
Expand Down
3 changes: 3 additions & 0 deletions src/keybind.h
Expand Up @@ -202,4 +202,7 @@ void kf_ToggleSpecOverlays();
void enableGodMode();

void keybindShutdown();

void keybindInformResourceExtractorRemoved(const STRUCTURE* psResourceExtractor);

#endif // __INCLUDED_SRC_KEYBIND_H__
3 changes: 3 additions & 0 deletions src/structure.cpp
Expand Up @@ -79,6 +79,7 @@
#include "scores.h"
#include "gateway.h"
#include "multistat.h"
#include "keybind.h"

#include "random.h"
#include <functional>
Expand Down Expand Up @@ -4348,6 +4349,8 @@ bool removeStruct(STRUCTURE *psDel, bool bDestroy)
{
//tell associated Power Gen
releaseResExtractor(psDel);
//tell keybind that this is going away (to prevent dangling pointer in kf_JumpToResourceExtractor)
keybindInformResourceExtractorRemoved(psDel);
}

if (psDel->pStructureType->type == REF_POWER_GEN)
Expand Down

0 comments on commit 9d15ce1

Please sign in to comment.