fyne-io / terminal

A graphical terminal emulator for Linux using Fyne
Other
252 stars 38 forks source link

Resolve panic on closing SSH session in fyne-io/terminal #84

Closed hq0101 closed 5 months ago

hq0101 commented 5 months ago

Resolve Panic on Closing SSH Session in fyne-io/terminal

Problem: When using the fyne-io/terminal library to establish an SSH connection, calling t.Exit() or session.Close() triggers a runtime panic "invalid memory address or nil pointer dereference". This occurs because t.cmd.Wait() is called in the Terminal.run method without prior initialization of t.cmd.

Root Cause: The issue stems from the RunWithConnection method where t.cmd is not set, but run() attempts to wait on this unassigned command object if an error occurs during stream reading, specifically after an SSH session ends.

Solution: This pull request introduces a nil check for t.cmd within the main loop of Terminal.run method. By checking if t.cmd is non-nil before attempting to call t.cmd.Wait(), we prevent the nil pointer dereference that leads to the application crash.

Detailed Changes:

Impact: This change significantly improves the stability and reliability of applications using the fyne-io/terminal library for managing SSH sessions, especially in scenarios where sessions might be dynamically controlled or terminated.

Your review and feedback would be highly appreciated to get this critical fix incorporated into the main branch. Thank you!