mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-16 08:13:30 +00:00
Added memory check to prevent potential crash
This commit is contained in:
@@ -393,7 +393,7 @@ ILibProcessPipe_Pipe ILibProcessPipe_Pipe_CreateFromExistingWithExtraMemory(ILib
|
|||||||
|
|
||||||
void ILibProcessPipe_Pipe_SetBrokenPipeHandler(ILibProcessPipe_Pipe targetPipe, ILibProcessPipe_Pipe_BrokenPipeHandler handler)
|
void ILibProcessPipe_Pipe_SetBrokenPipeHandler(ILibProcessPipe_Pipe targetPipe, ILibProcessPipe_Pipe_BrokenPipeHandler handler)
|
||||||
{
|
{
|
||||||
((ILibProcessPipe_PipeObject*)targetPipe)->brokenPipeHandler = (ILibProcessPipe_GenericBrokenPipeHandler)handler;
|
if (ILibMemory_CanaryOK(targetPipe)) { ((ILibProcessPipe_PipeObject*)targetPipe)->brokenPipeHandler = (ILibProcessPipe_GenericBrokenPipeHandler)handler; }
|
||||||
}
|
}
|
||||||
|
|
||||||
ILibProcessPipe_PipeObject* ILibProcessPipe_CreatePipe(ILibProcessPipe_Manager manager, int pipeBufferSize, ILibProcessPipe_GenericBrokenPipeHandler brokenPipeHandler, int extraMemorySize)
|
ILibProcessPipe_PipeObject* ILibProcessPipe_CreatePipe(ILibProcessPipe_Manager manager, int pipeBufferSize, ILibProcessPipe_GenericBrokenPipeHandler brokenPipeHandler, int extraMemorySize)
|
||||||
|
|||||||
@@ -343,6 +343,8 @@ void ILibWebClient_SetTimeout(ILibWebClient_StateObject state, int timeoutSecond
|
|||||||
// <param name="wr">The WebRequest to free</param>
|
// <param name="wr">The WebRequest to free</param>
|
||||||
void ILibWebClient_DestroyWebRequest(struct ILibWebRequest *wr)
|
void ILibWebClient_DestroyWebRequest(struct ILibWebRequest *wr)
|
||||||
{
|
{
|
||||||
|
if (!ILibMemory_CanaryOK(wr)) { return; }
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
struct ILibWebClient_StreamedRequestBuffer *b;
|
struct ILibWebClient_StreamedRequestBuffer *b;
|
||||||
|
|
||||||
@@ -389,7 +391,7 @@ void ILibWebClient_DestroyWebRequest(struct ILibWebRequest *wr)
|
|||||||
free(wr->requestToken);
|
free(wr->requestToken);
|
||||||
wr->requestToken = NULL;
|
wr->requestToken = NULL;
|
||||||
}
|
}
|
||||||
free(wr);
|
ILibMemory_Free(wr);
|
||||||
wr = NULL;
|
wr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2452,8 +2454,7 @@ ILibWebClient_StateObject ILibCreateWebClientEx(ILibWebClient_OnResponse OnRespo
|
|||||||
wcdo->SOCK = socketModule;
|
wcdo->SOCK = socketModule;
|
||||||
wcdo->PendingConnectionIndex = -1;
|
wcdo->PendingConnectionIndex = -1;
|
||||||
|
|
||||||
if ((wr = (struct ILibWebRequest*)malloc(sizeof(struct ILibWebRequest))) == NULL) ILIBCRITICALEXIT(254);
|
wr = (struct ILibWebRequest*)ILibMemory_SmartAllocate(sizeof(struct ILibWebRequest));
|
||||||
memset(wr, 0, sizeof(struct ILibWebRequest));
|
|
||||||
wr->OnResponse = OnResponse;
|
wr->OnResponse = OnResponse;
|
||||||
wr->user1 = user1;
|
wr->user1 = user1;
|
||||||
wr->user2 = user2;
|
wr->user2 = user2;
|
||||||
@@ -2633,10 +2634,7 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequestEx2(
|
|||||||
int indexWithLeast;
|
int indexWithLeast;
|
||||||
int numberOfItems;
|
int numberOfItems;
|
||||||
|
|
||||||
|
request = (struct ILibWebRequest*)ILibMemory_SmartAllocate(sizeof(struct ILibWebRequest));
|
||||||
if ((request = (struct ILibWebRequest*)malloc(sizeof(struct ILibWebRequest))) == NULL) ILIBCRITICALEXIT(254);
|
|
||||||
memset(request, 0, sizeof(struct ILibWebRequest));
|
|
||||||
|
|
||||||
request->NumberOfBuffers = bodyBuffer != NULL?2:1;
|
request->NumberOfBuffers = bodyBuffer != NULL?2:1;
|
||||||
if ((request->Buffer = (char**)malloc(request->NumberOfBuffers * sizeof(char*))) == NULL) ILIBCRITICALEXIT(254);
|
if ((request->Buffer = (char**)malloc(request->NumberOfBuffers * sizeof(char*))) == NULL) ILIBCRITICALEXIT(254);
|
||||||
if ((request->BufferLength = (size_t*)malloc(request->NumberOfBuffers * sizeof(size_t))) == NULL) ILIBCRITICALEXIT(254);
|
if ((request->BufferLength = (size_t*)malloc(request->NumberOfBuffers * sizeof(size_t))) == NULL) ILIBCRITICALEXIT(254);
|
||||||
@@ -3143,7 +3141,7 @@ void ILibWebClient_CancelRequestEx(void *chain, void *RequestToken)
|
|||||||
*/
|
*/
|
||||||
void ILibWebClient_CancelRequest(ILibWebClient_RequestToken RequestToken)
|
void ILibWebClient_CancelRequest(ILibWebClient_RequestToken RequestToken)
|
||||||
{
|
{
|
||||||
if (RequestToken != NULL)
|
if (ILibMemory_CanaryOK(RequestToken))
|
||||||
{
|
{
|
||||||
ILibChain_RunOnMicrostackThread(((struct ILibWebClient_PipelineRequestToken*)RequestToken)->wcdo->Parent->ChainLink.ParentChain, ILibWebClient_CancelRequestEx, RequestToken);
|
ILibChain_RunOnMicrostackThread(((struct ILibWebClient_PipelineRequestToken*)RequestToken)->wcdo->Parent->ChainLink.ParentChain, ILibWebClient_CancelRequestEx, RequestToken);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user