From cf481429a21e26b01b7814942021b291b80b4bf7 Mon Sep 17 00:00:00 2001
From: Ingo Ruhnke <grumbel@gmx.de>
Date: Wed, 29 Jul 2009 18:55:08 +0200
Subject: [PATCH] Do Proper cleanup in usb_read_thread.cpp

---
 TODO                    | 8 --------
 src/usb_read_thread.cpp | 5 +++++
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/TODO b/TODO
index 78f704a..aeb74b6 100644
--- a/TODO
+++ b/TODO
@@ -20,14 +20,6 @@ Stuff to do before 0.5 release:
 
 * figure out a way to make userspace force feedback driver not become dead processes
 
-* try out soft realtime scheduling: http://www.ddj.com/linux-open-source/184402031
-  to fix missed events on some controller
-
-  setting timeout = 0 fixes missing issues, but breaks relativeaxis and autofire
-  other alternative would be to go multithreaded
-
-  Write usb_thread.?pp thing to read usb data with timeout=0
-
 * add a --mimic-xpad option that behaves exactly like xpad
 
 * better keyboard emulation via analog sticks: axis must not be
diff --git a/src/usb_read_thread.cpp b/src/usb_read_thread.cpp
index 375a265..936a3f6 100644
--- a/src/usb_read_thread.cpp
+++ b/src/usb_read_thread.cpp
@@ -33,6 +33,11 @@ USBReadThread::USBReadThread(struct usb_dev_handle* handle, int endpoint, int le
 
 USBReadThread::~USBReadThread()
 {
+  if (!m_stop)
+    stop_thread();
+
+  for(std::list<Paket>::iterator i = m_read_buffer.begin(); i != m_read_buffer.end(); ++i)
+    delete[] i->data;
 }
   
 void