Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leak in XKeyboard::build_layout #30

Merged
merged 1 commit into from
May 17, 2019

Conversation

szaszm
Copy link
Contributor

@szaszm szaszm commented May 15, 2019

XkbRF_VarDefsRec seems to be intended to be used only through XkbRF_RulesRec.
It includes dynamically allocated C string, but provides no direct
cleanup method. This commit adds custom cleanup as a workaround.

A proper cleanup would complicate the code even more, so this is just a bandaid to avoid the leak while keeping the code relatively compact.

XkbRF_VarDefsRec: https://github.com/freedesktop/xorg-libxkbfile/blob/master/include/X11/extensions/XKBrules.h
cleanup in khurshid-alam/Unity-Settings-Daemon: https://github.com/khurshid-alam/Unity-Settings-Daemon/blob/7135a08b39e17401338232ee3f0309582dd31202/plugins/keyboard/gsd-xkb-utils.c#L78

XkbRF_VarDefsRec seems to be intended to be used only through XkbRF_RulesRec.
It includes dynamically allocated C string, but provides no direct
cleanup method. This commit adds custom cleanup as a workaround.

XkbRF_VarDefsRec: https://github.com/freedesktop/xorg-libxkbfile/blob/master/include/X11/extensions/XKBrules.h
cleanup in khurshid-alam/Unity-Settings-Daemon: https://github.com/khurshid-alam/Unity-Settings-Daemon/blob/7135a08b39e17401338232ee3f0309582dd31202/plugins/keyboard/gsd-xkb-utils.c#L78
@sergei-mironov
Copy link
Owner

sergei-mironov commented May 16, 2019

Good catch, thanks! Could you suggest a way to protect the code from possible failures due to XkbRF_VarDefsRec design changes?

Edit: What about extra_names extra_values fields?

@sergei-mironov
Copy link
Owner

Note, filed a bug https://bugs.freedesktop.org/show_bug.cgi?id=110696

@szaszm
Copy link
Contributor Author

szaszm commented May 17, 2019

I've spent an additional 2 hours googling a proper way to query the keyboard layout, still no success. I suggest we wait for a reply on the upstream bug report you just created.
Possibly interesting findings:

@sergei-mironov
Copy link
Owner

OK, thank you. I merge this PR, but leave the issue open.

@sergei-mironov sergei-mironov merged commit 31c040d into sergei-mironov:master May 17, 2019
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.

None yet

2 participants