Skip to content

Commit

Permalink
Fix memory leaks
Browse files Browse the repository at this point in the history
Reduce definitely lost

Switch us,jp,zh_CN,zh_TW,kr,ru and us.

Before:

  ==11333== LEAK SUMMARY:
  ==11333==    definitely lost: 47,787 bytes in 120 blocks
  ==11333==    indirectly lost: 11,202,985 bytes in 105,883 blocks
  ==11333==      possibly lost: 46,244 bytes in 682 blocks
  ==11333==    still reachable: 20,012,541 bytes in 82,152 blocks
  ==11333==                       of which reachable via heuristic:
  ==11333==                         length64           : 152,752 bytes in 377 blocks
  ==11333==                         newarray           : 1,568 bytes in 18 blocks
  ==11333==                         multipleinheritance: 3,816 bytes in 46 blocks
  ==11333==         suppressed: 0 bytes in 0 blocks

After:

  ==16589== LEAK SUMMARY:
  ==16589==    definitely lost: 46,208 bytes in 110 blocks
  ==16589==    indirectly lost: 9,753,601 bytes in 93,247 blocks
  ==16589==      possibly lost: 65,671 bytes in 832 blocks
  ==16589==    still reachable: 20,011,619 bytes in 82,144 blocks
  ==16589==                       of which reachable via heuristic:
  ==16589==                         length64           : 152,752 bytes in 377 blocks
  ==16589==                         newarray           : 1,568 bytes in 18 blocks
  ==16589==                         multipleinheritance: 14,136 bytes in 158 blocks
  ==16589==         suppressed: 0 bytes in 0 blocks

Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
  • Loading branch information
kenhys committed Jun 17, 2024
1 parent ea6556e commit ed1c094
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/virtualkeyboardanthy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ AnthyKeyboard::AnthyKeyboard()
<< "path of Japanese keyboard layout file: " << jsonPath;
loader_ = new KeyboardLayout(jsonPath);
}
AnthyKeyboard::~AnthyKeyboard() {
FCITX_KEYBOARD_LAYOUT() << "~AnthyKeyboard()";
delete loader_;
}
#else
AnthyKeyboard::AnthyKeyboard()
: typingMethodNameOfKana_(
Expand Down
1 change: 1 addition & 0 deletions src/virtualkeyboardanthy.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static const std::string anthyGetTextDomainName = "fcitx5-anthy";
class AnthyKeyboard : public I18nKeyboard {
public:
AnthyKeyboard();
~AnthyKeyboard() override;
KeyboardType type() const override { return KeyboardType::Anthy; };
const char *label() const override { return "JP"; }
const std::string languageCode() const override { return "ja"; }
Expand Down
4 changes: 4 additions & 0 deletions src/virtualkeyboardchewing.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class ChewingKeyboard : public I18nKeyboard {
<< jsonPath;
loader_ = new KeyboardLayout(jsonPath);
}
~ChewingKeyboard() override {
FCITX_KEYBOARD_LAYOUT() << "~ChewingKeyboard()";
delete loader_;
}
#endif

private:
Expand Down
5 changes: 5 additions & 0 deletions src/virtualkeyboardcustom.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class CustomKeyboard : public I18nKeyboard {
label_ = loader_->label();
languageCode_ = std::string(loader_->languageCode());
}
~CustomKeyboard() override {
FCITX_KEYBOARD_LAYOUT()
<< "~CustomKeyboard() " << label_ << ":" << languageCode_;
delete loader_;
}
int mode() { return mode_; }
void switchMode();
bool isAdditionalMarkOn() const { return isAdditionalMarkOn_; }
Expand Down
4 changes: 4 additions & 0 deletions src/virtualkeyboardhangul.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class HangulKeyboard : public I18nKeyboard {
FCITX_KEYBOARD() << "path of Korean keyboard layout file: " << jsonPath;
loader_ = new KeyboardLayout(jsonPath);
}
~HangulKeyboard() override {
FCITX_KEYBOARD_LAYOUT() << "~HangulKeyboard()";
delete loader_;
}
#endif

private:
Expand Down
3 changes: 3 additions & 0 deletions src/virtualkeyboardi18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class VirtualKey;
class VirtualKeyboard;
class I18nKeyboard {
public:
#if USE_CUSTOM_LAYOUT
virtual ~I18nKeyboard() {}
#endif
virtual KeyboardType type() const = 0;
virtual const char *label() const = 0;
virtual void updateKeys() = 0;
Expand Down
11 changes: 11 additions & 0 deletions src/virtualkeyboardlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ class KeyboardLayout {
}
}

~KeyboardLayout() {
FCITX_KEYBOARD_LAYOUT() << "~KeyboardLayout()";
keys_.clear();
stateLabels_.clear();
modeLabels_.clear();
modeActions_.clear();
modeOffsets_.clear();
// decrement the reference count
json_object_put(json_);
free(json_);
}
// Keyboard metadata
const char *label() { return label_; }
const char *languageCode() { return languageCode_; }
Expand Down
4 changes: 4 additions & 0 deletions src/virtualkeyboardpinyin.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class PinyinKeyboard : public I18nKeyboard {
FCITX_KEYBOARD() << "path of Korean keyboard layout file: " << jsonPath;
loader_ = new KeyboardLayout(jsonPath);
}
~PinyinKeyboard() override {
FCITX_KEYBOARD() << "~PinyinKeyboard()";
delete loader_;
}
#endif

private:
Expand Down
4 changes: 4 additions & 0 deletions src/virtualkeyboardrussian.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class RussianKeyboard : public I18nKeyboard {
<< jsonPath;
loader_ = new KeyboardLayout(jsonPath);
}
~RussianKeyboard() override {
FCITX_KEYBOARD() << "~RussianKeyboard()";
delete loader_;
}
#endif

private:
Expand Down
4 changes: 4 additions & 0 deletions src/virtualkeyboardus.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class UsKeyboard : public I18nKeyboard {
<< jsonPath;
loader_ = new KeyboardLayout(jsonPath);
}
~UsKeyboard() override {
FCITX_KEYBOARD() << "~UsKeyboard()";
delete loader_;
}
#endif

private:
Expand Down

0 comments on commit ed1c094

Please sign in to comment.