summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-06-24 20:53:43 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-06-24 20:53:43 +0300
commitc1b659192659698fe54cbfef9b1f9df77e59e7c7 (patch)
tree0b596f3d1cfbb41e6f2ccf8dcf0f143b0d2b65da /plugins
parente89d9f7aee35af5441ce8e3432f7eabdb7ffc5e3 (diff)
ProxySwitcher: fix for a crash on exit
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ProxySwitch/src/ip.cpp46
-rw-r--r--plugins/ProxySwitch/src/main.cpp2
-rw-r--r--plugins/ProxySwitch/src/stdafx.h4
3 files changed, 23 insertions, 29 deletions
diff --git a/plugins/ProxySwitch/src/ip.cpp b/plugins/ProxySwitch/src/ip.cpp
index 0741344294..7ae87a8d3d 100644
--- a/plugins/ProxySwitch/src/ip.cpp
+++ b/plugins/ProxySwitch/src/ip.cpp
@@ -12,15 +12,11 @@ the proxy settings of Miranda and Internet Explorer accordingly.
void IP_WatchDog(void*)
{
OVERLAPPED overlap;
- DWORD ret;
- wchar_t msg[300];
- HANDLE event_list[2];
- HANDLE hand = WSACreateEvent();
- overlap.hEvent = WSACreateEvent();
+ overlap.hEvent = CreateEvent(0, TRUE, FALSE, 0);
- for (;;) {
-
- ret = NotifyAddrChange(&hand, &overlap);
+ while (true) {
+ HANDLE hResult;
+ DWORD ret = NotifyAddrChange(&hResult, &overlap);
if (ret != NO_ERROR && WSAGetLastError() != WSA_IO_PENDING) {
wchar_t err[100];
mir_snwprintf(err, L"NotifyAddrChange Error: %d/nRestart Miranda NG to restore IP monitor.", WSAGetLastError());
@@ -28,6 +24,7 @@ void IP_WatchDog(void*)
break;
}
+ HANDLE event_list[2];
event_list[0] = overlap.hEvent;
event_list[1] = hEventRebound;
@@ -77,21 +74,20 @@ void IP_WatchDog(void*)
if (opt_alwayReconnect)
reset_Miranda = 1;
- mir_wstrcpy(msg, L"");
- if (opt_showProxyState && change_Miranda) {
- mir_wstrcat(msg, TranslateT("\nMiranda "));
- mir_wstrcat(msg, proxy ? TranslateT("Proxy") : TranslateT("Direct"));
- }
- if (opt_showProxyState && change_IE) {
- mir_wstrcat(msg, TranslateT("\nExplorer "));
- mir_wstrcat(msg, proxy ? TranslateT("Proxy") : TranslateT("Direct"));
- }
- if (opt_showProxyState && change_Firefox) {
- mir_wstrcat(msg, TranslateT("\nFirefox "));
- mir_wstrcat(msg, proxy ? TranslateT("Proxy") : TranslateT("Direct"));
+ const wchar_t *wszProxy = proxy ? TranslateT("Proxy") : TranslateT("Direct");
+ CMStringW msg;
+ if (opt_showProxyState) {
+ if (change_Miranda)
+ msg.AppendFormat(L"\n%s\t%s", TranslateT("Miranda"), wszProxy);
+
+ if (change_IE)
+ msg.AppendFormat(L"\n%s\t%s", TranslateT("Miranda"), wszProxy);
+
+ if (change_Firefox)
+ msg.AppendFormat(L"\n%s\t%s", TranslateT("Miranda"), wszProxy);
}
UpdateInterfacesMenu();
- PopupMyIPAddrs(mir_wstrlen(msg) ? msg : NULL);
+ PopupMyIPAddrs(msg.IsEmpty() ? nullptr : msg.c_str());
if (change_IE)
Set_IE_Proxy_Status(proxy);
@@ -110,12 +106,10 @@ void IP_WatchDog(void*)
}
ResetEvent(hEventRebound);
- WSAResetEvent(hand);
- WSAResetEvent(overlap.hEvent);
+ ResetEvent(overlap.hEvent);
}
- WSACloseEvent(hand);
- WSACloseEvent(overlap.hEvent);
+ CloseHandle(overlap.hEvent);
}
/* ################################################################################ */
@@ -421,7 +415,7 @@ wchar_t* Print_NIF(NETWORK_INTERFACE* nif)
return wszTemp.GetBuffer();
}
-wchar_t* Print_NIF_List(NETWORK_INTERFACE_LIST &list, wchar_t *msg)
+wchar_t* Print_NIF_List(NETWORK_INTERFACE_LIST &list, const wchar_t *msg)
{
wszTemp = L"";
for (auto &it : list) {
diff --git a/plugins/ProxySwitch/src/main.cpp b/plugins/ProxySwitch/src/main.cpp
index 48f76dbd9b..44fd01e464 100644
--- a/plugins/ProxySwitch/src/main.cpp
+++ b/plugins/ProxySwitch/src/main.cpp
@@ -71,7 +71,7 @@ static INT_PTR ShowMyIPAddrs(WPARAM, LPARAM)
return 0;
}
-void PopupMyIPAddrs(wchar_t *msg)
+void PopupMyIPAddrs(const wchar_t *msg)
{
OBJLIST<NETWORK_INTERFACE> list(10);
if (Create_NIF_List_Ex(&list) >= 0) {
diff --git a/plugins/ProxySwitch/src/stdafx.h b/plugins/ProxySwitch/src/stdafx.h
index 2e0f525950..5e73cc2a6c 100644
--- a/plugins/ProxySwitch/src/stdafx.h
+++ b/plugins/ProxySwitch/src/stdafx.h
@@ -116,7 +116,7 @@ void SaveSettings(void);
/**** Service & Event handlers *************************************************************/
-void PopupMyIPAddrs(wchar_t *msg);
+void PopupMyIPAddrs(const wchar_t *msg);
int OptInit(WPARAM wParam, LPARAM lParam);
int Init(WPARAM wParam, LPARAM lParam);
@@ -155,7 +155,7 @@ void IP_WatchDog(void *arg);
int Create_NIF_List(NETWORK_INTERFACE_LIST *list);
int Create_NIF_List_Ex(NETWORK_INTERFACE_LIST *list);
int IncUpdate_NIF_List(NETWORK_INTERFACE_LIST *trg, NETWORK_INTERFACE_LIST &src);
-wchar_t *Print_NIF_List(NETWORK_INTERFACE_LIST &list, wchar_t *msg);
+wchar_t *Print_NIF_List(NETWORK_INTERFACE_LIST &list, const wchar_t *msg);
wchar_t *Print_NIF(NETWORK_INTERFACE *nif);
int Create_Range_List(IP_RANGE_LIST *list, wchar_t *str, BOOL prioritized);