From 5145bc173be9fef13e02ba2b08a87c50d080377d Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Fri, 14 Jun 2024 18:12:37 +0900 Subject: [PATCH] Fix memory leaks Reduce definitely lost Before: ==5836== LEAK SUMMARY: ==5836== definitely lost: 99,435 bytes in 549 blocks ==5836== indirectly lost: 101,154,375 bytes in 881,013 blocks ==5836== possibly lost: 173,778 bytes in 1,678 blocks ==5836== still reachable: 20,033,236 bytes in 82,359 blocks After: ==7294== LEAK SUMMARY: ==7294== definitely lost: 93,155 bytes in 498 blocks ==7294== indirectly lost: 88,383,626 bytes in 772,926 blocks ==7294== possibly lost: 71,891 bytes in 902 blocks ==7294== still reachable: 20,016,025 bytes in 82,184 blocks ==7294== of which reachable via heuristic: --- src/virtualkeyboardcustom.h | 1 + src/virtualkeyboardlayout.h | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/virtualkeyboardcustom.h b/src/virtualkeyboardcustom.h index 0db356f..9585c3a 100644 --- a/src/virtualkeyboardcustom.h +++ b/src/virtualkeyboardcustom.h @@ -45,6 +45,7 @@ class CustomKeyboard : public I18nKeyboard { label_ = loader_->label(); languageCode_ = std::string(loader_->languageCode()); } + ~CustomKeyboard() { delete loader_; } int mode() { return mode_; } void switchMode(); bool isAdditionalMarkOn() const { return isAdditionalMarkOn_; } diff --git a/src/virtualkeyboardlayout.h b/src/virtualkeyboardlayout.h index 0982ff3..7316f6a 100644 --- a/src/virtualkeyboardlayout.h +++ b/src/virtualkeyboardlayout.h @@ -35,6 +35,13 @@ class KeyboardLayout { } } + ~KeyboardLayout() { + keys_.clear(); + stateLabels_.clear(); + modeLabels_.clear(); + modeActions_.clear(); + modeOffsets_.clear(); + } // Keyboard metadata const char *label() { return label_; } const char *languageCode() { return languageCode_; }