• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision10276 (tree)
Time2022-09-20 00:40:58
Authorzmatsuo

Log Message

新しい接続でcomポートが存在する時、メモリリークしていたので修正

- ComPortInfoGet() を使用するようにした

- DetectComPorts() を使用しないようにした

- ダイアログのプロシージャ関数内でstatic変数を使用しないようにした
- comポートの情報は動的なメモリ上に取得するので内部的には上限がなくなった

- tttypes.h で MAXCOMPORT は 4096 としてある

Change Summary

Incremental Difference

--- trunk/teraterm/ttpcmn/ttcmn.c (revision 10275)
+++ trunk/teraterm/ttpcmn/ttcmn.c (revision 10276)
@@ -67,16 +67,20 @@
6767
6868 void WINAPI SetCOMFlag(int Com)
6969 {
70+ if (Com <= 0 || MAXCOMPORT <= Com) return;
7071 pm->ComFlag[(Com-1)/CHAR_BIT] |= 1 << ((Com-1)%CHAR_BIT);
7172 }
7273
7374 void WINAPI ClearCOMFlag(int Com)
7475 {
76+ if (Com <= 0 || MAXCOMPORT <= Com) return;
7577 pm->ComFlag[(Com-1)/CHAR_BIT] &= ~(1 << ((Com-1)%CHAR_BIT));
7678 }
7779
7880 int WINAPI CheckCOMFlag(int Com)
7981 {
82+ if (Com <= 0) return 0;
83+ if (Com > MAXCOMPORT) return 1;
8084 return ((pm->ComFlag[(Com-1)/CHAR_BIT] & 1 << (Com-1)%CHAR_BIT) > 0);
8185 }
8286
--- trunk/teraterm/ttpdlg/ttdlg.c (revision 10275)
+++ trunk/teraterm/ttpdlg/ttdlg.c (revision 10276)
@@ -1647,6 +1647,12 @@
16471647 return FALSE;
16481648 }
16491649
1650+typedef struct {
1651+ PGetHNRec GetHNRec;
1652+ ComPortInfo_t *ComPortInfoPtr;
1653+ int ComPortInfoCount;
1654+} TTXHostDlgData;
1655+
16501656 static INT_PTR CALLBACK HostDlg(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam)
16511657 {
16521658 static const DlgTextInfo TextInfos[] = {
@@ -1660,19 +1666,20 @@
16601666 { IDCANCEL, "BTN_CANCEL" },
16611667 { IDC_HOSTHELP, "BTN_HELP" },
16621668 };
1663- PGetHNRec GetHNRec;
1664- char EntName[128];
1665- WORD i, j, w;
1666- BOOL Ok;
1667- WORD ComPortTable[MAXCOMPORT];
1668- static char *ComPortDesc[MAXCOMPORT];
1669- int comports;
1669+ TTXHostDlgData *dlg_data = (TTXHostDlgData *)GetWindowLongPtr(Dialog, DWLP_USER);
1670+ PGetHNRec GetHNRec = dlg_data != NULL ? dlg_data->GetHNRec : NULL;
16701671
16711672 switch (Message) {
1672- case WM_INITDIALOG:
1673+ case WM_INITDIALOG: {
1674+ WORD i;
1675+ int j;
16731676 GetHNRec = (PGetHNRec)lParam;
1674- SetWindowLongPtr(Dialog, DWLP_USER, lParam);
1677+ dlg_data = (TTXHostDlgData *)calloc(sizeof(*dlg_data), 1);
1678+ SetWindowLongPtr(Dialog, DWLP_USER, (LPARAM)dlg_data);
1679+ dlg_data->GetHNRec = GetHNRec;
16751680
1681+ dlg_data->ComPortInfoPtr = ComPortInfoGet(&dlg_data->ComPortInfoCount, NULL);
1682+
16761683 SetDlgTexts(Dialog, TextInfos, _countof(TextInfos), UILanguageFile);
16771684
16781685 // ファイルおよび名前付きパイプの場合、TCP/IP扱いとする。
@@ -1704,48 +1711,34 @@
17041711 SendDlgItemMessage(Dialog, IDC_HOSTTCPPROTOCOL, CB_SETCURSEL,0,0);
17051712
17061713 j = 0;
1707- w = 1;
1708- if ((comports=DetectComPorts(ComPortTable, GetHNRec->MaxComPort, ComPortDesc)) >= 0) {
1709- for (i=0; i<comports; i++) {
1710- // MaxComPort を越えるポートは表示しない
1711- if (ComPortTable[i] > GetHNRec->MaxComPort) {
1712- continue;
1713- }
1714+ for (i = 0; i < dlg_data->ComPortInfoCount; i++) {
1715+ ComPortInfo_t *p = dlg_data->ComPortInfoPtr + i;
1716+ wchar_t *EntNameW;
1717+ int index;
17141718
1715- // 使用中のポートは表示しない
1716- if (CheckCOMFlag(ComPortTable[i]) == 1) {
1717- continue;
1718- }
1719+ // MaxComPort を越えるポートは表示しない
1720+ if (GetHNRec->MaxComPort >= 0 && i > GetHNRec->MaxComPort) {
1721+ continue;
1722+ }
1723+ j++;
17191724
1720- _snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "COM%d", ComPortTable[i]);
1721- if (ComPortDesc[i] != NULL) {
1722- strncat_s(EntName, sizeof(EntName), ": ", _TRUNCATE);
1723- strncat_s(EntName, sizeof(EntName), ComPortDesc[i], _TRUNCATE);
1724- }
1725- SendDlgItemMessage(Dialog, IDC_HOSTCOM, CB_ADDSTRING,
1726- 0, (LPARAM)EntName);
1727- j++;
1728- if (GetHNRec->ComPort==ComPortTable[i]) {
1729- w = j;
1730- }
1725+ // 使用中のポートは表示しない
1726+ if (CheckCOMFlag(p->port_no) == 1) {
1727+ continue;
17311728 }
1732- } else {
1733- for (i=1; i<=GetHNRec->MaxComPort ;i++) {
1734- // 使用中のポートは表示しない
1735- if (CheckCOMFlag(i) == 1) {
1736- continue;
1737- }
1738- _snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "COM%d", i);
1739- SendDlgItemMessage(Dialog, IDC_HOSTCOM, CB_ADDSTRING,
1740- 0, (LPARAM)EntName);
1741- j++;
1742- if (GetHNRec->ComPort==i) {
1743- w = j;
1744- }
1729+
1730+ if (p->friendly_name == NULL) {
1731+ aswprintf(&EntNameW, L"%s", p->port_name);
17451732 }
1733+ else {
1734+ aswprintf(&EntNameW, L"%s: %s", p->port_name, p->friendly_name);
1735+ }
1736+ index = (int)SendDlgItemMessageW(Dialog, IDC_HOSTCOM, CB_ADDSTRING, 0, (LPARAM)EntNameW);
1737+ SendDlgItemMessageA(Dialog, IDC_HOSTCOM, CB_SETITEMDATA, index, i);
1738+ free(EntNameW);
17461739 }
17471740 if (j>0) {
1748- SendDlgItemMessage(Dialog, IDC_HOSTCOM, CB_SETCURSEL,w-1,0);
1741+ SendDlgItemMessage(Dialog, IDC_HOSTCOM, CB_SETCURSEL,0,0);
17491742 }
17501743 else { /* All com ports are already used */
17511744 GetHNRec->PortType = IdTCPIP;
@@ -1765,52 +1758,37 @@
17651758 CenterWindow(Dialog, GetParent(Dialog));
17661759
17671760 return TRUE;
1768-
1761+ }
17691762 case WM_COMMAND:
17701763 switch (LOWORD(wParam)) {
1771- case IDOK:
1772- GetHNRec = (PGetHNRec)GetWindowLongPtr(Dialog,DWLP_USER);
1773- if ( GetHNRec!=NULL ) {
1774- char afstr[BUFSIZ];
1775- GetRB(Dialog,&GetHNRec->PortType,IDC_HOSTTCPIP,IDC_HOSTSERIAL);
1776- if ( GetHNRec->PortType==IdTCPIP ) {
1777- GetDlgItemTextW(Dialog, IDC_HOSTNAME, GetHNRec->HostName, HostNameMaxLength);
1778- }
1779- else {
1780- GetHNRec->HostName[0] = 0;
1781- }
1782- GetRB(Dialog,&GetHNRec->Telnet,IDC_HOSTTELNET,IDC_HOSTTELNET);
1783- i = GetDlgItemInt(Dialog,IDC_HOSTTCPPORT,&Ok,FALSE);
1784- if (Ok) {
1785- GetHNRec->TCPPort = i;
1786- }
1787-#define getaf(str) \
1788- ((strcmp((str), "IPv6") == 0) ? AF_INET6 : \
1789- ((strcmp((str), "IPv4") == 0) ? AF_INET : AF_UNSPEC))
1790- memset(afstr, 0, sizeof(afstr));
1791- GetDlgItemText(Dialog, IDC_HOSTTCPPROTOCOL, afstr, sizeof(afstr));
1792- GetHNRec->ProtocolFamily = getaf(afstr);
1793- memset(EntName,0,sizeof(EntName));
1794- GetDlgItemText(Dialog, IDC_HOSTCOM, EntName, sizeof(EntName)-1);
1795- if (strncmp(EntName, "COM", 3) == 0 && EntName[3] != '\0') {
1796-#if 0
1797- GetHNRec->ComPort = (BYTE)(EntName[3])-0x30;
1798- if (strlen(EntName)>4)
1799- GetHNRec->ComPort = GetHNRec->ComPort*10 + (BYTE)(EntName[4])-0x30;
1800-#else
1801- GetHNRec->ComPort = atoi(&EntName[3]);
1802-#endif
1803- if (GetHNRec->ComPort > GetHNRec->MaxComPort) {
1804- GetHNRec->ComPort = 1;
1805- }
1806- }
1807- else {
1808- GetHNRec->ComPort = 1;
1809- }
1764+ case IDOK: {
1765+ int i;
1766+ int pos;
1767+ int index;
1768+ BOOL Ok;
1769+
1770+ GetRB(Dialog,&GetHNRec->PortType,IDC_HOSTTCPIP,IDC_HOSTSERIAL);
1771+ if ( GetHNRec->PortType==IdTCPIP ) {
1772+ GetDlgItemTextW(Dialog, IDC_HOSTNAME, GetHNRec->HostName, HostNameMaxLength);
18101773 }
1774+ else {
1775+ GetHNRec->HostName[0] = 0;
1776+ }
1777+ GetRB(Dialog,&GetHNRec->Telnet,IDC_HOSTTELNET,IDC_HOSTTELNET);
1778+ i = GetDlgItemInt(Dialog,IDC_HOSTTCPPORT,&Ok,FALSE);
1779+ if (Ok) {
1780+ GetHNRec->TCPPort = i;
1781+ }
1782+ i = (int)SendDlgItemMessage(Dialog, IDC_HOSTTCPPROTOCOL, CB_GETCURSEL, 0, 0);
1783+ GetHNRec->ProtocolFamily =
1784+ i == 0 ? AF_UNSPEC :
1785+ i == 1 ? AF_INET6 : AF_INET;
1786+ pos = (int)SendDlgItemMessageA(Dialog, IDC_HOSTCOM, CB_GETCURSEL, 0, 0);
1787+ index = (int)SendDlgItemMessageA(Dialog, IDC_HOSTCOM, CB_GETITEMDATA, pos, 0);
1788+ GetHNRec->ComPort = dlg_data->ComPortInfoPtr[index].port_no;
18111789 EndDialog(Dialog, 1);
18121790 return TRUE;
1813-
1791+ }
18141792 case IDCANCEL:
18151793 EndDialog(Dialog, 0);
18161794 return TRUE;
@@ -1827,15 +1805,14 @@
18271805 DisableDlgItem(Dialog,IDC_HOSTTCPPROTOCOLLABEL,IDC_HOSTTCPPROTOCOL);
18281806 break;
18291807
1830- case IDC_HOSTTELNET:
1808+ case IDC_HOSTTELNET: {
1809+ WORD i;
18311810 GetRB(Dialog,&i,IDC_HOSTTELNET,IDC_HOSTTELNET);
18321811 if ( i==1 ) {
1833- GetHNRec = (PGetHNRec)GetWindowLongPtr(Dialog,DWLP_USER);
1834- if ( GetHNRec!=NULL ) {
1835- SetDlgItemInt(Dialog,IDC_HOSTTCPPORT,GetHNRec->TelPort,FALSE);
1836- }
1812+ SetDlgItemInt(Dialog,IDC_HOSTTCPPORT,GetHNRec->TelPort,FALSE);
18371813 }
18381814 break;
1815+ }
18391816
18401817 case IDC_HOSTCOM:
18411818 if(HIWORD(wParam) == CBN_DROPDOWN) {
@@ -1864,6 +1841,11 @@
18641841 PostMessage(GetParent(Dialog),WM_USER_DLGHELP2,HlpFileNewConnection,0);
18651842 break;
18661843 }
1844+ break;
1845+ case WM_DESTROY:
1846+ ComPortInfoFree(dlg_data->ComPortInfoPtr, dlg_data->ComPortInfoCount);
1847+ free(dlg_data);
1848+ break;
18671849 }
18681850 return FALSE;
18691851 }
--- trunk/ttssh2/ttxssh/ttxssh.c (revision 10275)
+++ trunk/ttssh2/ttxssh/ttxssh.c (revision 10276)
@@ -96,6 +96,7 @@
9696 #include "inifile_com.h"
9797 #include "asprintf.h"
9898 #include "win32helper.h"
99+#include "comportinfo.h"
99100
100101 #include "libputty.h"
101102
@@ -978,8 +979,13 @@
978979 }
979980 }
980981
981-static INT_PTR CALLBACK TTXHostDlg(HWND dlg, UINT msg, WPARAM wParam,
982- LPARAM lParam)
982+typedef struct {
983+ PGetHNRec GetHNRec;
984+ ComPortInfo_t *ComPortInfoPtr;
985+ int ComPortInfoCount;
986+} TTXHostDlgData;
987+
988+static INT_PTR CALLBACK TTXHostDlg(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
983989 {
984990 static const DlgTextInfo text_info[] = {
985991 { 0, "DLG_HOST_TITLE" },
@@ -998,18 +1004,21 @@
9981004 };
9991005 static const char *ssh_version[] = {"SSH1", "SSH2", NULL};
10001006 static const char *ProtocolFamilyList[] = { "AUTO", "IPv6", "IPv4", NULL };
1001- PGetHNRec GetHNRec;
1002- char EntName[128];
1003- WORD i, j, w;
1004- WORD ComPortTable[MAXCOMPORT];
1005- static char *ComPortDesc[MAXCOMPORT];
1006- int comports;
1007+ TTXHostDlgData *dlg_data = (TTXHostDlgData *)GetWindowLongPtr(dlg, DWLP_USER);
1008+ PGetHNRec GetHNRec = dlg_data != NULL ? dlg_data->GetHNRec : NULL;
1009+ WORD i;
10071010
10081011 switch (msg) {
1009- case WM_INITDIALOG:
1010- GetHNRec = (PGetHNRec) lParam;
1011- SetWindowLongPtr(dlg, DWLP_USER, lParam);
1012+ case WM_INITDIALOG: {
1013+ int j;
10121014
1015+ GetHNRec = (PGetHNRec)lParam;
1016+ dlg_data = (TTXHostDlgData *)calloc(sizeof(*dlg_data), 1);
1017+ SetWindowLongPtr(dlg, DWLP_USER, (LPARAM)dlg_data);
1018+ dlg_data->GetHNRec = GetHNRec;
1019+
1020+ dlg_data->ComPortInfoPtr = ComPortInfoGet(&dlg_data->ComPortInfoCount, NULL);
1021+
10131022 SetI18nDlgStrsW(dlg, "TTSSH", text_info, _countof(text_info), pvar->ts->UILanguageFileW);
10141023
10151024 // ホストヒストリのチェックボックスを追加 (2005.10.21 yutaka)
@@ -1070,50 +1079,35 @@
10701079
10711080
10721081 j = 0;
1073- w = 1;
1074- comports = DetectComPorts(ComPortTable, GetHNRec->MaxComPort, ComPortDesc);
1075- if (comports >= 0) {
1076- for (i=0; i<comports; i++) {
1077- // MaxComPort を越えるポートは表示しない
1078- if (ComPortTable[i] > GetHNRec->MaxComPort) {
1079- continue;
1080- }
1082+ for (i = 0; i < dlg_data->ComPortInfoCount; i++) {
1083+ ComPortInfo_t *p = dlg_data->ComPortInfoPtr + i;
1084+ wchar_t *EntNameW;
1085+ int index;
10811086
1082- // 使用中のポートは表示しない
1083- if (CheckCOMFlag(ComPortTable[i]) == 1) {
1084- continue;
1085- }
1087+ // MaxComPort を越えるポートは表示しない
1088+ if (GetHNRec->MaxComPort >= 0 && i > GetHNRec->MaxComPort) {
1089+ continue;
1090+ }
1091+ j++;
10861092
1087- _snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "COM%d", ComPortTable[i]);
1088- if (ComPortDesc[i] != NULL) {
1089- strncat_s(EntName, sizeof(EntName), ": ", _TRUNCATE);
1090- strncat_s(EntName, sizeof(EntName), ComPortDesc[i], _TRUNCATE);
1091- }
1092- SendDlgItemMessage(dlg, IDC_HOSTCOM, CB_ADDSTRING,
1093- 0, (LPARAM)EntName);
1094- j++;
1095- if (GetHNRec->ComPort == ComPortTable[i])
1096- w = j;
1093+ // 使用中のポートは表示しない
1094+ if (CheckCOMFlag(p->port_no) == 1) {
1095+ continue;
10971096 }
10981097
1099- } else {
1100- for (i = 1; i <= GetHNRec->MaxComPort; i++) {
1101- // 使用中のポートは表示しない
1102- if (CheckCOMFlag(i) == 1) {
1103- continue;
1104- }
1105-
1106- _snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "COM%d", i);
1107- SendDlgItemMessage(dlg, IDC_HOSTCOM, CB_ADDSTRING,
1108- 0, (LPARAM) EntName);
1109- j++;
1110- if (GetHNRec->ComPort == i)
1111- w = j;
1098+ if (p->friendly_name == NULL) {
1099+ aswprintf(&EntNameW, L"%s", p->port_name);
11121100 }
1101+ else {
1102+ aswprintf(&EntNameW, L"%s: %s", p->port_name, p->friendly_name);
1103+ }
1104+ index = (int)SendDlgItemMessageW(dlg, IDC_HOSTCOM, CB_ADDSTRING, 0, (LPARAM)EntNameW);
1105+ SendDlgItemMessageA(dlg, IDC_HOSTCOM, CB_SETITEMDATA, index, i);
1106+ free(EntNameW);
11131107 }
11141108
11151109 if (j > 0)
1116- SendDlgItemMessage(dlg, IDC_HOSTCOM, CB_SETCURSEL, w - 1, 0);
1110+ SendDlgItemMessage(dlg, IDC_HOSTCOM, CB_SETCURSEL, 0, 0); // select first com port
11171111 else { /* All com ports are already used */
11181112 GetHNRec->PortType = IdTCPIP;
11191113 enable_dlg_items(dlg, IDC_HOSTSERIAL, IDC_HOSTSERIAL, FALSE);
@@ -1160,69 +1154,63 @@
11601154 // (2004.11.23 yutaka)
11611155 return FALSE;
11621156 //return TRUE;
1157+ }
11631158
11641159 case WM_COMMAND:
11651160 switch (LOWORD(wParam)) {
11661161 case IDOK:
1167- GetHNRec = (PGetHNRec) GetWindowLongPtr(dlg, DWLP_USER);
1168- if (GetHNRec != NULL) {
1169- if (IsDlgButtonChecked(dlg, IDC_HOSTTCPIP)) {
1170- BOOL Ok;
1171- i = GetDlgItemInt(dlg, IDC_HOSTTCPPORT, &Ok, FALSE);
1172- if (!Ok) {
1173- // TODO IDC_HOSTTCPPORTは数値しか入力できない、不要?
1174- static const TTMessageBoxInfoW info = {
1175- "TTSSH",
1176- NULL, L"Tera Term",
1177- "MSG_TCPPORT_NAN_ERROR", L"The TCP port must be a number.",
1178- MB_OK | MB_ICONEXCLAMATION
1179- };
1180- TTMessageBoxA(dlg, &info, pvar->ts->UILanguageFile);
1181- return TRUE;
1182- }
1183- GetHNRec->TCPPort = i;
1184- i = (int)SendDlgItemMessage(dlg, IDC_HOSTTCPPROTOCOL, CB_GETCURSEL, 0, 0);
1185- GetHNRec->ProtocolFamily =
1186- i == 0 ? AF_UNSPEC :
1187- i == 1 ? AF_INET6 : AF_INET;
1188- GetHNRec->PortType = IdTCPIP;
1189- GetDlgItemTextW(dlg, IDC_HOSTNAME, GetHNRec->HostName, HostNameMaxLength);
1190- pvar->hostdlg_activated = TRUE;
1191- pvar->hostdlg_Enabled = FALSE;
1192- if (IsDlgButtonChecked(dlg, IDC_HOSTTELNET)) {
1193- GetHNRec->Telnet = TRUE;
1194- } else if (IsDlgButtonChecked(dlg, IDC_HOSTSSH)) {
1195- pvar->hostdlg_Enabled = TRUE;
1162+ if (IsDlgButtonChecked(dlg, IDC_HOSTTCPIP)) {
1163+ BOOL Ok;
1164+ i = GetDlgItemInt(dlg, IDC_HOSTTCPPORT, &Ok, FALSE);
1165+ if (!Ok) {
1166+ // TODO IDC_HOSTTCPPORTは数値しか入力できない、不要?
1167+ static const TTMessageBoxInfoW info = {
1168+ "TTSSH",
1169+ NULL, L"Tera Term",
1170+ "MSG_TCPPORT_NAN_ERROR", L"The TCP port must be a number.",
1171+ MB_OK | MB_ICONEXCLAMATION
1172+ };
1173+ TTMessageBoxA(dlg, &info, pvar->ts->UILanguageFile);
1174+ return TRUE;
1175+ }
1176+ GetHNRec->TCPPort = i;
1177+ i = (int)SendDlgItemMessage(dlg, IDC_HOSTTCPPROTOCOL, CB_GETCURSEL, 0, 0);
1178+ GetHNRec->ProtocolFamily =
1179+ i == 0 ? AF_UNSPEC :
1180+ i == 1 ? AF_INET6 : AF_INET;
1181+ GetHNRec->PortType = IdTCPIP;
1182+ GetDlgItemTextW(dlg, IDC_HOSTNAME, GetHNRec->HostName, HostNameMaxLength);
1183+ pvar->hostdlg_activated = TRUE;
1184+ pvar->hostdlg_Enabled = FALSE;
1185+ if (IsDlgButtonChecked(dlg, IDC_HOSTTELNET)) {
1186+ GetHNRec->Telnet = TRUE;
1187+ } else if (IsDlgButtonChecked(dlg, IDC_HOSTSSH)) {
1188+ pvar->hostdlg_Enabled = TRUE;
11961189
1197- // check SSH protocol version
1198- i = (int)SendDlgItemMessage(dlg, IDC_SSH_VERSION, CB_GETCURSEL, 0, 0);
1199- pvar->settings.ssh_protocol_version = (i == 0) ? 1 : 2;
1200- }
1201- else { // IDC_HOSTOTHER
1202- GetHNRec->Telnet = FALSE;
1203- }
1190+ // check SSH protocol version
1191+ i = (int)SendDlgItemMessage(dlg, IDC_SSH_VERSION, CB_GETCURSEL, 0, 0);
1192+ pvar->settings.ssh_protocol_version = (i == 0) ? 1 : 2;
1193+ }
1194+ else { // IDC_HOSTOTHER
1195+ GetHNRec->Telnet = FALSE;
1196+ }
12041197
1205- // host history check button
1206- if (SendMessage(GetDlgItem(dlg, IDC_HISTORY), BM_GETCHECK, 0, 0) == BST_CHECKED) {
1207- pvar->ts->HistoryList = 1;
1208- } else {
1209- pvar->ts->HistoryList = 0;
1210- }
1211-
1198+ // host history check button
1199+ if (SendMessage(GetDlgItem(dlg, IDC_HISTORY), BM_GETCHECK, 0, 0) == BST_CHECKED) {
1200+ pvar->ts->HistoryList = 1;
12121201 } else {
1213- GetHNRec->PortType = IdSerial;
1214- GetHNRec->HostName[0] = 0;
1215- memset(EntName, 0, sizeof(EntName));
1216- GetDlgItemText(dlg, IDC_HOSTCOM, EntName,
1217- sizeof(EntName) - 1);
1218- if (strncmp(EntName, "COM", 3) == 0 && EntName[3] != '\0') {
1219- GetHNRec->ComPort = atoi(&EntName[3]);
1220- if (GetHNRec->ComPort > GetHNRec->MaxComPort)
1221- GetHNRec->ComPort = 1;
1222- } else {
1223- GetHNRec->ComPort = 1;
1224- }
1202+ pvar->ts->HistoryList = 0;
12251203 }
1204+
1205+ } else {
1206+ int pos;
1207+ int index;
1208+
1209+ GetHNRec->PortType = IdSerial;
1210+ GetHNRec->HostName[0] = 0;
1211+ pos = (int)SendDlgItemMessageA(dlg, IDC_HOSTCOM, CB_GETCURSEL, 0, 0);
1212+ index = (int)SendDlgItemMessageA(dlg, IDC_HOSTCOM, CB_GETITEMDATA, pos, 0);
1213+ GetHNRec->ComPort = dlg_data->ComPortInfoPtr[index].port_no;
12261214 }
12271215 EndDialog(dlg, 1);
12281216 return TRUE;
@@ -1272,12 +1260,8 @@
12721260 enable_dlg_items(dlg, IDC_SSH_VERSION, IDC_SSH_VERSION, FALSE); // disabled
12731261 hostssh_enabled:
12741262
1275- GetHNRec = (PGetHNRec) GetWindowLongPtr(dlg, DWLP_USER);
1276-
12771263 if (IsDlgButtonChecked(dlg, IDC_HOSTTELNET)) {
1278- if (GetHNRec != NULL)
1279- SetDlgItemInt(dlg, IDC_HOSTTCPPORT, GetHNRec->TelPort,
1280- FALSE);
1264+ SetDlgItemInt(dlg, IDC_HOSTTCPPORT, GetHNRec->TelPort, FALSE);
12811265 } else if (IsDlgButtonChecked(dlg, IDC_HOSTSSH)) {
12821266 SetDlgItemInt(dlg, IDC_HOSTTCPPORT, 22, FALSE);
12831267 }
@@ -1286,6 +1270,11 @@
12861270 case IDC_HOSTHELP:
12871271 PostMessage(GetParent(dlg), WM_USER_DLGHELP2, HlpFileNewConnection, 0);
12881272 }
1273+ break;
1274+ case WM_DESTROY:
1275+ ComPortInfoFree(dlg_data->ComPortInfoPtr, dlg_data->ComPortInfoCount);
1276+ free(dlg_data);
1277+ break;
12891278 }
12901279 return FALSE;
12911280 }
@@ -1301,8 +1290,7 @@
13011290 SetDialogFont(pvar->ts->DialogFontNameW, pvar->ts->DialogFontPoint, pvar->ts->DialogFontCharSet,
13021291 pvar->ts->UILanguageFileW, "TTSSH", "DLG_TAHOMA_FONT");
13031292 // pvar->ts->UILanguageFile, "TTSSH", "DLG_SYSTEM_FONT");
1304- return (BOOL) DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_HOSTDLG),
1305- parent, TTXHostDlg, (LPARAM)rec);
1293+ return (BOOL)DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_HOSTDLG), parent, TTXHostDlg, (LPARAM)rec);
13061294 }
13071295
13081296 static void PASCAL TTXGetUIHooks(TTXUIHooks *hooks)
Show on old repository browser