Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Unified Diff: ui/base/touch/touch_factory.cc

Issue 9333005: Fix some memory leaks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/valgrind/memcheck/suppressions.txt ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/touch/touch_factory.cc
diff --git a/ui/base/touch/touch_factory.cc b/ui/base/touch/touch_factory.cc
index b636ea05d7b444ccd651ee73b1a47fc592391a51..e89d5ed0dbfedcc50ab5e2e82623acdac33a6f60 100644
--- a/ui/base/touch/touch_factory.cc
+++ b/ui/base/touch/touch_factory.cc
@@ -17,6 +17,23 @@
namespace {
+// Keeps track of a string returned by an X function (e.g. XGetAtomName) and
+// makes sure it's XFree'd.
+class XScopedString {
sky 2012/02/06 21:43:00 Should this live in ui/base/x?
sadrul 2012/02/07 19:45:24 Sounds like a good idea. I moved this into x11_uti
+ public:
+ explicit XScopedString(const char *str) : string_(str) { }
+ ~XScopedString() {
+ XFree(string_);
+ }
+
+ const char *string() const { return string_; }
+
+ private:
+ const char *string_;
+
+ DISALLOW_COPY_AND_ASSIGN(XScopedString);
+};
+
// The X cursor is hidden if it is idle for kCursorIdleSeconds seconds.
int kCursorIdleSeconds = 5;
@@ -64,8 +81,8 @@ XIValuatorClassInfo* FindTPValuator(Display* display,
reinterpret_cast<XIValuatorClassInfo*>(info->classes[i]);
if (v->label) {
- const char* atom = XGetAtomName(display, v->label);
- if (atom && strcmp(atom, atom_tp) == 0)
+ XScopedString atom(XGetAtomName(display, v->label));
+ if (atom.string() && strcmp(atom.string(), atom_tp) == 0)
return v;
}
}
@@ -151,8 +168,8 @@ void TouchFactory::UpdateDeviceList(Display* display) {
XDeviceInfo* devlist = XListInputDevices(display, &count);
for (int i = 0; i < count; i++) {
if (devlist[i].type) {
- const char* devtype = XGetAtomName(display, devlist[i].type);
- if (devtype && !strcmp(devtype, XI_TOUCHSCREEN)) {
+ XScopedString devtype(XGetAtomName(display, devlist[i].type));
+ if (devtype.string() && !strcmp(devtype.string(), XI_TOUCHSCREEN)) {
touch_device_lookup_[devlist[i].id] = true;
touch_device_list_[devlist[i].id] = true;
touch_device_available_ = true;
« no previous file with comments | « tools/valgrind/memcheck/suppressions.txt ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698