From 53c279b9e96da8b69837ae84038a78ca5707f2a5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Jul 2010 10:45:02 -0700 Subject: altosui: Close serial, join reader thread, free altos_file Separating out the close and free actions ensures that the reader thread will not access freed memory or dereference a null pointer while shutting down the connection to the serial device. Otherwise, a race condition exists between the serial close and the thread join. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ao-tools/altosui/AltosSerial.java') diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 96e8b61f..efa63f68 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -51,8 +51,6 @@ public class AltosSerial implements Runnable { try { for (;;) { - if (altos == null) - break; c = libaltos.altos_getchar(altos, 0); if (Thread.interrupted()) break; @@ -106,10 +104,8 @@ public class AltosSerial implements Runnable { } public void close() { - if (altos != null) { + if (altos != null) libaltos.altos_close(altos); - altos = null; - } if (input_thread != null) { try { input_thread.interrupt(); @@ -118,6 +114,10 @@ public class AltosSerial implements Runnable { } input_thread = null; } + if (altos != null) { + libaltos.altos_free(altos); + altos = null; + } } public void putc(char c) { -- cgit v1.2.3