diff --git a/microscript/ILibDuktape_GenericMarshal.c b/microscript/ILibDuktape_GenericMarshal.c index 6ff10b2..8159fb6 100644 --- a/microscript/ILibDuktape_GenericMarshal.c +++ b/microscript/ILibDuktape_GenericMarshal.c @@ -1630,7 +1630,7 @@ void* ILibDuktape_GlobalGenericCallback_Process(int numParms, ...) while (node != NULL) { data = (Duktape_GlobalGeneric_Data*)ILibLinkedList_GetDataFromNode(node); - refList[count++] = data; + if (data != NULL) { refList[count++] = data; } node = ILibLinkedList_GetNextNode(node); } ILibLinkedList_UnLock(GlobalCallbackList); @@ -2045,7 +2045,7 @@ duk_ret_t ILibDuktape_GenericMarshal_Finalizer(duk_context *ctx) while (node != NULL) { Duktape_GlobalGeneric_Data *data = (Duktape_GlobalGeneric_Data*)ILibLinkedList_GetDataFromNode(node); - if (data->chain == duk_ctx_chain(ctx) && data->ctxnonce == duk_ctx_nonce(ctx)) + if (data != NULL && data->chain == duk_ctx_chain(ctx) && data->ctxnonce == duk_ctx_nonce(ctx)) { ILibMemory_Free(data); void *next = ILibLinkedList_GetNextNode(node); diff --git a/microscript/ILibDuktape_Helpers.c b/microscript/ILibDuktape_Helpers.c index 9b8f376..7a412e7 100644 --- a/microscript/ILibDuktape_Helpers.c +++ b/microscript/ILibDuktape_Helpers.c @@ -779,7 +779,10 @@ void Duktape_SafeDestroyHeap(duk_context *ctx) void *node; while ((node = ILibLinkedList_GetNode_Head(ctxd->threads)) != NULL) { - threadList[i++] = ILibLinkedList_GetDataFromNode(node); + if (ILibLinkedList_GetDataFromNode(node) != NULL) + { + threadList[i++] = ILibLinkedList_GetDataFromNode(node); + } ILibLinkedList_Remove(node); } while (WaitForMultipleObjectsEx(i, threadList, TRUE, 1000, TRUE) == WAIT_IO_COMPLETION); @@ -793,10 +796,12 @@ void Duktape_SafeDestroyHeap(duk_context *ctx) ILibThread_ms2ts(5000, &ts); while ((node = ILibLinkedList_GetNode_Head(ctxd->threads)) != NULL) { - thr = ILibLinkedList_GetDataFromNode(node); - if ((rv = ILibThread_TimedJoinEx(thr, &ts)) != 0) + if ((thr = ILibLinkedList_GetDataFromNode(node)) != NULL) { - break; + if ((rv = ILibThread_TimedJoinEx(thr, &ts)) != 0) + { + break; + } } ILibLinkedList_Remove(node); } diff --git a/microstack/ILibParsers.c b/microstack/ILibParsers.c index 27b8459..2fb1cb5 100644 --- a/microstack/ILibParsers.c +++ b/microstack/ILibParsers.c @@ -1748,7 +1748,10 @@ void ILibChain_SignalSink(int signum) void *node = ILibLinkedList_GetNode_Head(g_signalHandlers[signum]); while (node != NULL) { - ignore_result(write(((ILibChain_SignalHandlerData*)ILibLinkedList_GetDataFromNode(node))->ipc[1], " ", 1)); + if (ILibLinkedList_GetDataFromNode(node) != NULL) + { + ignore_result(write(((ILibChain_SignalHandlerData*)ILibLinkedList_GetDataFromNode(node))->ipc[1], " ", 1)); + } node = ILibLinkedList_GetNextNode(node); } } @@ -1935,6 +1938,7 @@ void ILibChain_SafeRemoveEx(void *chain, void *object) */ void ILibChain_SafeRemove(void *chain, void *object) { + if (object == NULL) { return; } ((ILibChain_Link*)object)->RESERVED = 0xFFFFFFFF; if (ILibIsChainBeingDestroyed(chain) == 0) { @@ -3303,7 +3307,11 @@ char *ILibChain_GetMetadataForTimers(void *chain) node = ILibLinkedList_GetNode_Head(LifeTimeMonitor->ObjectList); while (node != NULL) { - Temp = (struct LifeTimeMonitorData*)ILibLinkedList_GetDataFromNode(node); + if ((Temp = (struct LifeTimeMonitorData*)ILibLinkedList_GetDataFromNode(node)) == NULL) + { + node = ILibLinkedList_GetNextNode(node); + continue; + } double ex = (double)(Temp->ExpirationTick - current); char *units = "milliseconds"; @@ -7418,8 +7426,10 @@ long long ILibLifeTime_GetExpiration(void *LifetimeMonitorObject, void *data) node = ILibLinkedList_GetNode_Head(LifeTimeMonitor->ObjectList); while (node != NULL) { - temp = (struct LifeTimeMonitorData*)ILibLinkedList_GetDataFromNode(node); - if (temp->data == data) return temp->ExpirationTick; + if ((temp = (struct LifeTimeMonitorData*)ILibLinkedList_GetDataFromNode(node)) != NULL) + { + if (temp->data == data) return temp->ExpirationTick; + } node = ILibLinkedList_GetNextNode(node); } return -1; @@ -7484,11 +7494,13 @@ ILibLifeTime_Token ILibLifeTime_AddEx4(void *LifetimeMonitorObject, void *data, { while (node != NULL) { - temp = (struct LifeTimeMonitorData*)ILibLinkedList_GetDataFromNode(node); - if (ltms->ExpirationTick < temp->ExpirationTick) + if ((temp = (struct LifeTimeMonitorData*)ILibLinkedList_GetDataFromNode(node)) != NULL) { - ILibLinkedList_InsertBefore(node, ltms); - break; + if (ltms->ExpirationTick < temp->ExpirationTick) + { + ILibLinkedList_InsertBefore(node, ltms); + break; + } } node = ILibLinkedList_GetNextNode(node); } @@ -7566,7 +7578,11 @@ void ILibLifeTime_Check(void *LifeTimeMonitorObject, fd_set *readset, fd_set *wr node = ILibLinkedList_GetNode_Head(LifeTimeMonitor->ObjectList); while (node != NULL) { - Temp = (struct LifeTimeMonitorData*)ILibLinkedList_GetDataFromNode(node); + if ((Temp = (struct LifeTimeMonitorData*)ILibLinkedList_GetDataFromNode(node)) == NULL) + { + node = ILibLinkedList_GetNextNode(node); + continue; + } if (Temp->ExpirationTick == 0 || Temp->ExpirationTick < CurrentTick) { ILibQueue_EnQueue(EventQueue, Temp); @@ -7648,7 +7664,7 @@ void ILibLifeTime_Remove(void *LifeTimeToken, void *data) while (node != NULL) { evt = (struct LifeTimeMonitorData*)ILibLinkedList_GetDataFromNode(node); - if (evt->data == data) + if (evt!=NULL && evt->data == data) { ILibQueue_EnQueue(EventQueue, evt); node = ILibLinkedList_Remove(node); @@ -8736,10 +8752,11 @@ void* ILibSparseArray_GetEx(ILibSparseArray sarray, int index, int remove) { // Need to check the Linked List void *listNode = ILibLinkedList_GetNode_Search(root->bucket[i].ptr, &ILibSparseArray_Comparer, (void*)&index); - retVal = listNode != NULL ? ((ILibSparseArray_Node*)ILibLinkedList_GetDataFromNode(listNode))->ptr : NULL; + retVal = listNode == NULL ? NULL : (ILibLinkedList_GetDataFromNode(listNode) == NULL ? NULL : ((ILibSparseArray_Node*)ILibLinkedList_GetDataFromNode(listNode))->ptr); + if(remove!=0 && listNode!=NULL) { - free(ILibLinkedList_GetDataFromNode(listNode)); + if (ILibLinkedList_GetDataFromNode(listNode) != NULL) { free(ILibLinkedList_GetDataFromNode(listNode)); } ILibLinkedList_Remove(listNode); if(ILibLinkedList_GetCount(root->bucket[i].ptr)==0) { @@ -8811,8 +8828,11 @@ void ILibSparseArray_ClearEx2(ILibSparseArray sarray, ILibSparseArray_OnValue on while(node != NULL) { ILibSparseArray_Node *sn = (ILibSparseArray_Node*)ILibLinkedList_GetDataFromNode(node); - if(onClear!=NULL) { onClear(sarray, sn->index, sn->ptr, user);} - if (nonZeroWillDelete != 0) { free(sn); } + if (sn != NULL) + { + if (onClear != NULL) { onClear(sarray, sn->index, sn->ptr, user); } + if (nonZeroWillDelete != 0) { free(sn); } + } node = ILibLinkedList_GetNextNode(node); } if (nonZeroWillDelete != 0) { ILibLinkedList_Destroy(root->bucket[i].ptr); } diff --git a/microstack/ILibProcessPipe.c b/microstack/ILibProcessPipe.c index a169cfc..f3983bd 100644 --- a/microstack/ILibProcessPipe.c +++ b/microstack/ILibProcessPipe.c @@ -190,7 +190,7 @@ char * ILibProcessPipe_Manager_OnQuery(void *chain, void *object, int fd, size_t if (node != NULL) { ILibProcessPipe_PipeObject *pj = (ILibProcessPipe_PipeObject*)ILibLinkedList_GetDataFromNode(node); - if (pj->metadata != NULL) + if (pj!=NULL && pj->metadata != NULL) { *dataLen = strnlen_s(pj->metadata, 1024); ret = pj->metadata; diff --git a/microstack/ILibWebClient.c b/microstack/ILibWebClient.c index 152c9ba..4aca2a7 100644 --- a/microstack/ILibWebClient.c +++ b/microstack/ILibWebClient.c @@ -3048,7 +3048,7 @@ void ILibWebClient_CancelRequestEx2(ILibWebClient_StateObject wcdo, void *userRe nextnode = ILibLinkedList_GetNextNode(node); wr = (struct ILibWebRequest*)ILibLinkedList_GetDataFromNode(node); - if (wr->requestToken == userRequest) + if (wr != NULL && wr->requestToken == userRequest) { if (node == head) { diff --git a/microstack/ILibWebRTC.c b/microstack/ILibWebRTC.c index d4fff15..aa4640d 100644 --- a/microstack/ILibWebRTC.c +++ b/microstack/ILibWebRTC.c @@ -3168,7 +3168,7 @@ int ILibStun_SctpAddSackChunk(struct ILibStun_Module *obj, int session, char* pa // Skip all packets with a low TSN. We do ths bacause we have not processed them yet, but will after adding this SACK void *node = ILibLinkedList_GetNode_Head(obj->dTlsSessions[session]->receiveHoldBuffer); - while(node!=NULL && ntohl(((ILibSCTP_DataPayload*)ILibLinkedList_GetDataFromNode(node))->TSN) <= obj->dTlsSessions[session]->userTSN) + while(node!=NULL && ILibLinkedList_GetDataFromNode(node) != NULL && ntohl(((ILibSCTP_DataPayload*)ILibLinkedList_GetDataFromNode(node))->TSN) <= obj->dTlsSessions[session]->userTSN) { node = ILibLinkedList_GetNextNode(node); } @@ -3177,9 +3177,9 @@ int ILibStun_SctpAddSackChunk(struct ILibStun_Module *obj, int session, char* pa while (node != NULL) { ILibSCTP_DataPayload *p = (ILibSCTP_DataPayload*)ILibLinkedList_GetDataFromNode(node); - unsigned int gstart = ntohl(p->TSN); + unsigned int gstart = (p == NULL ? 0 : ntohl(p->TSN)); unsigned int gend = gstart; - bytecount += ntohs(p->length); + bytecount += (p == NULL ? 0 : ntohs(p->length)); node = ILibLinkedList_GetNextNode(node); while (node != NULL && (p = (ILibSCTP_DataPayload*)ILibLinkedList_GetDataFromNode(node))!=NULL) @@ -3638,7 +3638,7 @@ void ILibStun_SctpDisconnect_Final(void *obj) node = ILibLinkedList_GetNode_Head(o->receiveHoldBuffer); while(node != NULL) { - free(ILibLinkedList_GetDataFromNode(node)); + if (ILibLinkedList_GetDataFromNode(node) != NULL) { free(ILibLinkedList_GetDataFromNode(node)); } node = ILibLinkedList_GetNextNode(node); } ILibLinkedList_Destroy(o->receiveHoldBuffer); @@ -5205,7 +5205,7 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char* rqptr = ILibLinkedList_GetNode_Head(o->receiveHoldBuffer); while (rqptr != NULL) { - unsigned int tsnx = ntohl(((ILibSCTP_DataPayload*)ILibLinkedList_GetDataFromNode(rqptr))->TSN); + unsigned int tsnx = (ILibLinkedList_GetDataFromNode(rqptr) == NULL ? 0 : ntohl(((ILibSCTP_DataPayload*)ILibLinkedList_GetDataFromNode(rqptr))->TSN)); if (tsnx != o->intsn + 1) break; ILibRemoteLogging_printf(ILibChainGetLogger(obj->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_3, "TSN Moved Forward to: %u", tsnx); o->intsn = tsnx; diff --git a/microstack/ILibWrapperWebRTC.c b/microstack/ILibWrapperWebRTC.c index fa50e3f..4b80a1d 100644 --- a/microstack/ILibWrapperWebRTC.c +++ b/microstack/ILibWrapperWebRTC.c @@ -831,11 +831,12 @@ void ILibWrapper_WebRTC_ConnectionFactory_RemoveFromChainSink(void *chain, void while (node != NULL && finished == 0) { - obj = (ILibChain_Link*)ILibLinkedList_GetDataFromNode(node); - - if (obj == turnClient) { finished = 1; } - if (obj->DestroyHandler != NULL) { obj->DestroyHandler(obj); } - ILibChain_FreeLink(obj); + if ((obj = (ILibChain_Link*)ILibLinkedList_GetDataFromNode(node)) != NULL) + { + if (obj == turnClient) { finished = 1; } + if (obj->DestroyHandler != NULL) { obj->DestroyHandler(obj); } + ILibChain_FreeLink(obj); + } node = ILibLinkedList_Remove(node); } }