From c76cb483df20f8058deedcf5500b20ea5af98cf6 Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Mon, 7 Sep 2015 15:30:02 +0000 Subject: VKontakte: code refactoring fix memory leaks and corruption fix for support MessageState version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@15294 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/vk_search.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'protocols/VKontakte/src/vk_search.cpp') diff --git a/protocols/VKontakte/src/vk_search.cpp b/protocols/VKontakte/src/vk_search.cpp index dbd6ff57b9..9180ca6c1c 100644 --- a/protocols/VKontakte/src/vk_search.cpp +++ b/protocols/VKontakte/src/vk_search.cpp @@ -85,17 +85,23 @@ void __cdecl CVkProto::SearchThread(void* p) Push(pReq); } +void CVkProto::FreeProtoShearchStruct(PROTOSEARCHBYNAME *pParam) +{ + if (!pParam) + return; + + mir_free(pParam->pszFirstName); + mir_free(pParam->pszLastName); + mir_free(pParam->pszNick); + delete pParam; +} + void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) { PROTOSEARCHBYNAME *pParam = (PROTOSEARCHBYNAME *)pReq->pUserInfo; debugLogA("CVkProto::OnSearch %d", reply->resultCode); if (reply->resultCode != 200) { - if (pParam) { - mir_free(pParam->pszFirstName); - mir_free(pParam->pszLastName); - mir_free(pParam->pszNick); - delete pParam; - } + FreeProtoShearchStruct(pParam); ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1); return; } @@ -103,12 +109,7 @@ void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) JSONNode jnRoot; const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot); if (!jnResponse) { - if (pParam) { - mir_free(pParam->pszFirstName); - mir_free(pParam->pszLastName); - mir_free(pParam->pszNick); - delete pParam; - } + FreeProtoShearchStruct(pParam); ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1); return; } @@ -148,12 +149,7 @@ void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) } ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1); - if (pParam) { - mir_free(pParam->pszFirstName); - mir_free(pParam->pszLastName); - mir_free(pParam->pszNick); - delete pParam; - } + FreeProtoShearchStruct(pParam); } void CVkProto::OnSearchByMail(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) -- cgit v1.2.3