Skip to content

Security: Potential Memory Leak in Singleton Pattern#1082

Open
tomaioo wants to merge 1 commit into
OpenGATE:masterfrom
tomaioo:fix/security/potential-memory-leak-in-singleton-patte
Open

Security: Potential Memory Leak in Singleton Pattern#1082
tomaioo wants to merge 1 commit into
OpenGATE:masterfrom
tomaioo:fix/security/potential-memory-leak-in-singleton-patte

Conversation

@tomaioo

@tomaioo tomaioo commented Jul 2, 2026

Copy link
Copy Markdown

Summary

Security: Potential Memory Leak in Singleton Pattern

Problem

Severity: Low | File: core/opengate_core/opengate_lib/GateActorManager.cpp:L13

In GateActorManager.cpp, the singleton pattern uses raw new without a corresponding delete, and the destructor is defaulted. The fInstance pointer is never deleted, which could lead to memory leaks. While this is a minor issue for a singleton that lives for the program duration, it represents poor memory management practice.

Solution

Use std::unique_ptr for the singleton instance to ensure proper cleanup, or implement a proper destruction mechanism. Consider using the Meyers' singleton pattern for thread-safe initialization without manual memory management.

Changes

  • core/opengate_core/opengate_lib/GateActorManager.cpp (modified)

In `GateActorManager.cpp`, the singleton pattern uses raw `new` without a corresponding `delete`, and the destructor is defaulted. The `fInstance` pointer is never deleted, which could lead to memory leaks. While this is a minor issue for a singleton that lives for the program duration, it represents poor memory management practice.

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant