summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTobias Weimer <wishmaster51@googlemail.com>2015-01-11 16:50:04 +0000
committerTobias Weimer <wishmaster51@googlemail.com>2015-01-11 16:50:04 +0000
commit78cee590285371ff574a957801024bcb6e75040f (patch)
tree530d61d57234b7d5816ffe32bf138251b20ab54d /src
parenta8e0f6b67fdfb0e8fcc7fe0394e78198501025bc (diff)
Core: Fixed minor memory leaks
git-svn-id: http://svn.miranda-ng.org/main/trunk@11830 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r--src/modules/findadd/searchresults.cpp132
-rw-r--r--src/modules/netlib/netlibopenconn.cpp18
2 files changed, 72 insertions, 78 deletions
diff --git a/src/modules/findadd/searchresults.cpp b/src/modules/findadd/searchresults.cpp
index db711e7c15..3f37798d6a 100644
--- a/src/modules/findadd/searchresults.cpp
+++ b/src/modules/findadd/searchresults.cpp
@@ -38,16 +38,13 @@ enum {
void SaveColumnSizes(HWND hwndResults)
{
int columnOrder[NUM_COLUMNID];
- int columnCount;
- char szSetting[32];
- int i;
- struct FindAddDlgData *dat;
- dat = (struct FindAddDlgData*)GetWindowLongPtr(GetParent(hwndResults), GWLP_USERDATA);
- columnCount = Header_GetItemCount(ListView_GetHeader(hwndResults));
+ struct FindAddDlgData *dat = (struct FindAddDlgData*)GetWindowLongPtr(GetParent(hwndResults), GWLP_USERDATA);
+ int columnCount = Header_GetItemCount(ListView_GetHeader(hwndResults));
if (columnCount != NUM_COLUMNID) return;
ListView_GetColumnOrderArray(hwndResults, columnCount, columnOrder);
- for (i=0; i < NUM_COLUMNID; i++) {
+ for (int i=0; i < NUM_COLUMNID; i++) {
+ char szSetting[32];
mir_snprintf(szSetting, SIZEOF(szSetting), "ColOrder%d", i);
db_set_b(NULL, "FindAdd", szSetting, (BYTE)columnOrder[i]);
if (i>=columnCount) continue;
@@ -66,16 +63,14 @@ void LoadColumnSizes(HWND hwndResults, const char *szProto)
int columnOrder[NUM_COLUMNID];
int columnCount;
char szSetting[32];
- int i;
- FindAddDlgData *dat;
bool colOrdersValid;
defaultColumnSizes[COLUMNID_PROTO] = GetSystemMetrics(SM_CXSMICON) + 4;
- dat = (FindAddDlgData*)GetWindowLongPtr(GetParent(hwndResults), GWLP_USERDATA);
+ FindAddDlgData *dat = (FindAddDlgData*)GetWindowLongPtr(GetParent(hwndResults), GWLP_USERDATA);
columnCount = NUM_COLUMNID;
colOrdersValid = true;
- for (i=0; i < NUM_COLUMNID; i++)
+ for (int i=0; i < NUM_COLUMNID; i++)
{
LVCOLUMN lvc;
if (i < columnCount)
@@ -174,11 +169,10 @@ int CALLBACK SearchResultsCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lPa
void FreeSearchResults(HWND hwndResults)
{
LV_ITEM lvi;
- struct ListSearchResult *lsr;
for (lvi.iItem = ListView_GetItemCount(hwndResults)-1;lvi.iItem>=0;lvi.iItem--) {
lvi.mask = LVIF_PARAM;
ListView_GetItem(hwndResults, &lvi);
- lsr = (struct ListSearchResult*)lvi.lParam;
+ struct ListSearchResult *lsr = (struct ListSearchResult*)lvi.lParam;
if (lsr == NULL) continue;
mir_free(lsr->psr.id);
mir_free(lsr->psr.email);
@@ -256,10 +250,8 @@ void SetStatusBarSearchInfo(HWND hwndStatus, struct FindAddDlgData *dat)
TCHAR str[256];
if (dat->searchCount != 0) {
- int i;
-
mir_tstrcpy(str, TranslateT("Searching"));
- for (i=0; i < dat->searchCount; i++) {
+ for (int i=0; i < dat->searchCount; i++) {
PROTOACCOUNT *pa = Proto_GetAccount(dat->search[i].szProto);
if (!pa)
continue;
@@ -279,51 +271,56 @@ struct ProtoResultsSummary {
};
void SetStatusBarResultInfo(HWND hwndDlg)
{
- HWND hwndStatus = GetDlgItem(hwndDlg, IDC_STATUSBAR);
HWND hwndResults = GetDlgItem(hwndDlg, IDC_RESULTS);
- LV_ITEM lvi;
- struct ListSearchResult *lsr;
- struct ProtoResultsSummary *subtotal = NULL;
- int subtotalCount = 0;
- int i, total;
TCHAR str[256];
-
- total = ListView_GetItemCount(hwndResults);
- for (lvi.iItem = total-1;lvi.iItem>=0;lvi.iItem--) {
- lvi.mask = LVIF_PARAM;
- ListView_GetItem(hwndResults, &lvi);
- lsr = (struct ListSearchResult*)lvi.lParam;
- if (lsr == NULL) continue;
- for (i=0;i<subtotalCount;i++) {
- if (subtotal[i].szProto == lsr->szProto) {
- subtotal[i].count++;
- break;
+ int total = ListView_GetItemCount(hwndResults);
+ if (total != 0) {
+ LV_ITEM lvi;
+ struct ProtoResultsSummary *subtotal = NULL;
+ int subtotalCount = 0;
+ for (lvi.iItem = total-1;lvi.iItem>=0;lvi.iItem--) {
+ lvi.mask = LVIF_PARAM;
+ ListView_GetItem(hwndResults, &lvi);
+ struct ListSearchResult *lsr = (struct ListSearchResult*)lvi.lParam;
+ if (lsr == NULL)
+ continue;
+ int i = 0;
+ while (i<subtotalCount) {
+ if (subtotal[i].szProto == lsr->szProto) {
+ subtotal[i].count++;
+ break;
+ }
+ else
+ i++;
+ }
+ if (i == subtotalCount) {
+ subtotal = (struct ProtoResultsSummary*)mir_realloc(subtotal, sizeof(struct ProtoResultsSummary)*(subtotalCount+1));
+ subtotal[subtotalCount].szProto = lsr->szProto;
+ subtotal[subtotalCount++].count = 1;
}
}
- if (i == subtotalCount) {
- subtotal = (struct ProtoResultsSummary*)mir_realloc(subtotal, sizeof(struct ProtoResultsSummary)*(subtotalCount+1));
- subtotal[subtotalCount].szProto = lsr->szProto;
- subtotal[subtotalCount++].count = 1;
- }
- }
- if (total != 0) {
- TCHAR substr[64];
- PROTOACCOUNT *pa = Proto_GetAccount(subtotal[0].szProto);
- if (pa == NULL)
- return;
-
if (subtotalCount == 1) {
- if (total == 1) mir_sntprintf(str, SIZEOF(str), TranslateT("1 %s user found"), pa->tszAccountName);
- else mir_sntprintf(str, SIZEOF(str), TranslateT("%d %s users found"), total, pa->tszAccountName);
+ PROTOACCOUNT *pa = Proto_GetAccount(subtotal[0].szProto);
+ if (pa == NULL) {
+ mir_free(subtotal);
+ return;
+ }
+ else if (total == 1)
+ mir_sntprintf(str, SIZEOF(str), TranslateT("1 %s user found"), pa->tszAccountName);
+ else
+ mir_sntprintf(str, SIZEOF(str), TranslateT("%d %s users found"), total, pa->tszAccountName);
}
else {
mir_sntprintf(str, SIZEOF(str), TranslateT("%d users found ("), total);
- for (i=0; i < subtotalCount; i++) {
- if (i) {
- if ((pa = Proto_GetAccount(subtotal[i].szProto)) == NULL)
- return;
+ for (int i=0; i < subtotalCount; i++) {
+ PROTOACCOUNT *pa = Proto_GetAccount(subtotal[i].szProto);
+ if (pa == NULL)
+ continue;
+
+ if (i)
mir_tstrcat(str, _T(", "));
- }
+
+ TCHAR substr[64];
mir_sntprintf(substr, SIZEOF(substr), _T("%d %s"), subtotal[i].count, pa->tszAccountName);
mir_tstrcat(str, substr);
}
@@ -332,7 +329,7 @@ void SetStatusBarResultInfo(HWND hwndDlg)
mir_free(subtotal);
}
else mir_tstrcpy(str, TranslateT("No users found"));
- SendMessage(hwndStatus, SB_SETTEXT, 2, (LPARAM)str);
+ SendDlgItemMessage(hwndDlg, IDC_STATUSBAR, SB_SETTEXT, 2, (LPARAM)str);
}
void CreateResultsColumns(HWND hwndResults, struct FindAddDlgData *dat, char *szProto)
@@ -345,26 +342,19 @@ void CreateResultsColumns(HWND hwndResults, struct FindAddDlgData *dat, char *sz
void ShowMoreOptionsMenu(HWND hwndDlg, int x, int y)
{
- struct FindAddDlgData *dat;
- HMENU hPopupMenu, hMenu;
- int commandId;
- struct ListSearchResult *lsr;
-
- dat = (struct FindAddDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ struct FindAddDlgData *dat = (struct FindAddDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- {
- LVITEM lvi;
- if (ListView_GetSelectedCount( GetDlgItem(hwndDlg, IDC_RESULTS)) != 1) return;
- lvi.mask = LVIF_PARAM;
- lvi.iItem = ListView_GetNextItem( GetDlgItem(hwndDlg, IDC_RESULTS), -1, LVNI_ALL|LVNI_SELECTED);
- ListView_GetItem( GetDlgItem(hwndDlg, IDC_RESULTS), &lvi);
- lsr = (struct ListSearchResult*)lvi.lParam;
- }
+ LVITEM lvi;
+ if (ListView_GetSelectedCount( GetDlgItem(hwndDlg, IDC_RESULTS)) != 1) return;
+ lvi.mask = LVIF_PARAM;
+ lvi.iItem = ListView_GetNextItem( GetDlgItem(hwndDlg, IDC_RESULTS), -1, LVNI_ALL|LVNI_SELECTED);
+ ListView_GetItem( GetDlgItem(hwndDlg, IDC_RESULTS), &lvi);
+ struct ListSearchResult *lsr = (struct ListSearchResult*)lvi.lParam;
- hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXT));
- hPopupMenu = GetSubMenu(hMenu, 4);
+ HMENU hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXT));
+ HMENU hPopupMenu = GetSubMenu(hMenu, 4);
TranslateMenu(hPopupMenu);
- commandId = TrackPopupMenu(hPopupMenu, TPM_RIGHTBUTTON|TPM_RETURNCMD, x, y, 0, hwndDlg, NULL);
+ int commandId = TrackPopupMenu(hPopupMenu, TPM_RIGHTBUTTON|TPM_RETURNCMD, x, y, 0, hwndDlg, NULL);
switch(commandId) {
case IDC_ADD:
{
@@ -384,7 +374,7 @@ void ShowMoreOptionsMenu(HWND hwndDlg, int x, int y)
case IDC_SENDMESSAGE:
{
MCONTACT hContact = (MCONTACT)CallProtoServiceInt(NULL, lsr->szProto, PS_ADDTOLIST, PALF_TEMPORARY, (LPARAM)&lsr->psr);
- CallService(MS_MSG_SENDMESSAGE, hContact, (LPARAM)(const char*)NULL);
+ CallService(MS_MSG_SENDMESSAGE, hContact, 0);
break;
}
}
diff --git a/src/modules/netlib/netlibopenconn.cpp b/src/modules/netlib/netlibopenconn.cpp
index 45adb2c88b..c7daa9dea2 100644
--- a/src/modules/netlib/netlibopenconn.cpp
+++ b/src/modules/netlib/netlibopenconn.cpp
@@ -496,15 +496,15 @@ retry:
return rc == 0;
}
-static bool my_connectIPv6(NetlibConnection *nlc, NETLIBOPENCONNECTION * nloc)
+static bool my_connectIPv6(NetlibConnection *nlc, NETLIBOPENCONNECTION *nloc)
{
+ if (!nloc)
+ return false;
+
int rc = SOCKET_ERROR, retrycnt = 0;
u_long notblocking = 1;
DWORD lasterr = 0;
static const TIMEVAL tv = { 1, 0 };
-
- if (!nloc)
- return false;
unsigned int dwTimeout = (nloc->cbSize == sizeof(NETLIBOPENCONNECTION) && nloc->flags & NLOCF_V2) ? nloc->timeout : 0;
// if dwTimeout is zero then its an old style connection or new with a 0 timeout, select() will error quicker anyway
if (dwTimeout == 0) dwTimeout = 30;
@@ -565,12 +565,16 @@ static bool my_connectIPv6(NetlibConnection *nlc, NETLIBOPENCONNECTION * nloc)
NetlibLogf(nlc->nlu, "(%p) Connecting to ip %s ....", nlc, ptrA(NetlibAddressToString((SOCKADDR_INET_M*)ai->ai_addr)));
retry:
nlc->s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
- if (nlc->s == INVALID_SOCKET)
+ if (nlc->s == INVALID_SOCKET) {
+ FreeAddrInfoA(air);
return false;
+ }
// return the socket to non blocking
- if (ioctlsocket(nlc->s, FIONBIO, &notblocking) != 0)
+ if (ioctlsocket(nlc->s, FIONBIO, &notblocking) != 0) {
+ FreeAddrInfoA(air);
return false;
+ }
if (nlc->nlu->settings.specifyOutgoingPorts && nlc->nlu->settings.szOutgoingPorts && nlc->nlu->settings.szOutgoingPorts[0]) {
SOCKET s = ai->ai_family == AF_INET ? nlc->s : INVALID_SOCKET;
@@ -657,7 +661,7 @@ retry:
return rc == 0;
}
-static bool my_connect(NetlibConnection *nlc, NETLIBOPENCONNECTION * nloc)
+static bool my_connect(NetlibConnection *nlc, NETLIBOPENCONNECTION *nloc)
{
return my_connectIPv6(nlc, nloc);
}