I have the following code:
if ((ptCurEntry->pNext = (TISOMStscBoxEntry *) malloc(sizeof(TISOMStscBoxEntry))) == NULL)
{
return ERR_OUT_OF_MEMORY;
}
ptCurEntry->pNext->pNext = NULL;
I malloc a space which is the size of TISOMStscBoxEntry
.
In this structure, there is a pointer pNext included.
In normal case, ptCurEntry->pNext->pNext = NULL
is worked.
(Just assign NULL to that created pointer)
However, I got segmentation fault which was caused by ptCurEntry->pNext->pNext = NULL
when the system was busy.
It seems like the error handling above for malloc is fine, what's wrong with it?
Maybe I cannot rely on the returned NULL of malloc?