Commit b9189597 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

xkblayoutengine: fix memory leak by unrefing keymap from buffer.

Wayland may supply xkb layout engine with a keymap that it creates
from a buffer. However, when I ran events_unittests with asan,
it noticed a memory leak, which was caused by not freed keymap
object.

As long as we can have only one keymap from buffer at a time,
store each keymap after a new context is created as unique_ptr
that will be freed with a custom deleter on either dtor or when
another keymap is created.

Bug: 1120270
Change-Id: I741a6cb74713424f54dd858f84c0fec413cd6c44
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2367938Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Commit-Queue: Maksim Sisov (GMT+3) <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#800708}
parent efb31116
...@@ -816,6 +816,10 @@ bool XkbKeyboardLayoutEngine::SetCurrentLayoutFromBuffer( ...@@ -816,6 +816,10 @@ bool XkbKeyboardLayoutEngine::SetCurrentLayoutFromBuffer(
return false; return false;
SetKeymap(keymap); SetKeymap(keymap);
// Store the keymap that will be unrefed either on dtor or if a new keymap is
// created.
key_map_from_buffer_.reset(keymap);
return true; return true;
} }
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include "ui/events/ozone/layout/keyboard_layout_engine.h" #include "ui/events/ozone/layout/keyboard_layout_engine.h"
#include "ui/events/ozone/layout/xkb/xkb_key_code_converter.h" #include "ui/events/ozone/layout/xkb/xkb_key_code_converter.h"
struct xkb_keymap;
namespace ui { namespace ui {
class COMPONENT_EXPORT(EVENTS_OZONE_LAYOUT) XkbKeyboardLayoutEngine class COMPONENT_EXPORT(EVENTS_OZONE_LAYOUT) XkbKeyboardLayoutEngine
...@@ -124,6 +126,9 @@ class COMPONENT_EXPORT(EVENTS_OZONE_LAYOUT) XkbKeyboardLayoutEngine ...@@ -124,6 +126,9 @@ class COMPONENT_EXPORT(EVENTS_OZONE_LAYOUT) XkbKeyboardLayoutEngine
std::unique_ptr<xkb_context, XkbContextDeleter> xkb_context_; std::unique_ptr<xkb_context, XkbContextDeleter> xkb_context_;
// Holds the keymap from xkb_keymap_new_from_buffer.
std::unique_ptr<xkb_keymap, XkbKeymapDeleter> key_map_from_buffer_;
std::string current_layout_name_; std::string current_layout_name_;
xkb_layout_index_t layout_index_ = 0; xkb_layout_index_t layout_index_ = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment