1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-12-26 18:19:53 +03:00

Merge PR #841: Mayaqua: fix segmentation fault, add new FreeSafe() function

This commit is contained in:
Davide Beatrici 2018-12-20 03:19:43 +01:00 committed by GitHub
commit 3c3aa900b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 14 deletions

View File

@ -3777,6 +3777,13 @@ void Free(void *addr)
InternalFree(tag);
}
// Free and set pointer's value to NULL
void FreeSafe(void **addr)
{
Free(*addr);
*addr = NULL;
}
// Check the memtag
void CheckMemTag(MEMTAG *tag)
{

View File

@ -276,6 +276,7 @@ void *ZeroMalloc(UINT size);
void *ZeroMallocEx(UINT size, bool zero_clear_when_free);
void *ReAlloc(void *addr, UINT size);
void Free(void *addr);
void FreeSafe(void **addr);
void CheckMemTag(MEMTAG *tag);
UINT GetMemSize(void *addr);

View File

@ -20563,13 +20563,15 @@ HTTP_HEADER *RecvHttpHeader(SOCK *s)
// Split into tokens
token = ParseToken(str, " ");
FreeSafe((void **)&str);
if (token->NumTokens < 3)
{
goto LABEL_ERROR;
FreeToken(token);
return NULL;
}
Free(str);
// Creating a header object
header = NewHttpHeader(token->Token[0], token->Token[1], token->Token[2]);
FreeToken(token);
@ -20588,27 +20590,21 @@ HTTP_HEADER *RecvHttpHeader(SOCK *s)
if (IsEmptyStr(str))
{
// End of header
Free(str);
FreeSafe((void **)&str);
break;
}
if (AddHttpValueStr(header, str) == false)
{
goto LABEL_ERROR;
FreeSafe((void **)&str);
FreeHttpHeader(header);
break;
}
Free(str);
FreeSafe((void **)&str);
}
return header;
LABEL_ERROR:
// Memory release
Free(str);
FreeToken(token);
FreeHttpHeader(header);
return NULL;
}
// Receive a line