From 77291967029c1f0d72224582f82dfe8b8515d627 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Fri, 21 Apr 2006 15:48:17 +0000 Subject: [PATCH] Close the pty if the session creation failed. --- debug/org.eclipse.cdt.debug.mi.core/ChangeLog | 4 ++ .../eclipse/cdt/debug/mi/core/MIPlugin.java | 50 ++++++++++++++----- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog index 99c5c6c9dbe..0c30706f864 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog @@ -1,3 +1,7 @@ +2006-04-21 Mikhail Khodjaiants + Close the pty if the session creation failed. + * MIPlugin.java + 2006-04-18 Mikhail Khodjaiants Duplicate message key. * MIPluginResources.properties diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java index eea0c2621c7..7d5e8c13270 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java @@ -434,23 +434,49 @@ public class MIPlugin extends Plugin { } String[] args = (String[])argList.toArray(new String[argList.size()]); int launchTimeout = MIPlugin.getDefault().getPluginPreferences().getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT); - MIProcess pgdb = new MIProcessAdapter(args, launchTimeout, monitor); - if (MIPlugin.getDefault().isDebugging()) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < args.length; ++i) { - sb.append(args[i]); - sb.append(' '); - } - MIPlugin.getDefault().debugLog(sb.toString()); - } - - MISession miSession; + MISession miSession = null; + MIProcess pgdb = null; + boolean failed = false; try { + pgdb = new MIProcessAdapter(args, launchTimeout, monitor); + + if (MIPlugin.getDefault().isDebugging()) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < args.length; ++i) { + sb.append(args[i]); + sb.append(' '); + } + MIPlugin.getDefault().debugLog(sb.toString()); + } + miSession = createMISession0(sessionType, pgdb, factory, pty, getCommandTimeout()); } catch (MIException e) { - pgdb.destroy(); + failed = true; throw e; + } catch(IOException e ) { + failed = true; + throw e; + } finally { + if (failed) { + // Kill gdb + if ( pgdb != null ) + pgdb.destroy(); + // Shutdown the pty console. + if (pty != null) { + try { + OutputStream out = pty.getOutputStream(); + if (out != null) { + out.close(); + } + InputStream in = pty.getInputStream(); + if (in != null) { + in.close(); + } + } catch (IOException e) { + } + } + } } return new Session(miSession);