Hello,
I am stuck with a kernel panic, and thought I know which line of code causes it, I can't understand the source of the error.
The code is located in a network kernel extension.
In FirstFile.h file, I declare a structure and a function:
struct anObject
{
void** pointerArray;
};
void initObject (struct anObject* theObject);
In FirstFile.c I implement the function:
void initObject(struct anObject* theObject)
{
theObject->pointerArray = OSMalloc(….);
}
In SecondFile.c file, I declare a static variable :
static struct anObject myObject = { NULL };
and I call:
initObject(&myObject);
This will cause the kernel panic. Specifically the line with OSMalloc in initObject(…).
What I can tell :
- &myObject != NULL;
- &myObject->pointerArray == NULL;
- the OSMallocTag I use with OSMalloc is valid. And works for any other call
- The size I want to alloc is very reasonable (40 Bytes)
Also, I am wondering… could this be linked to the use of static variables ?
A few days ago, I decided to replace a dynamically allocated structure (OSMalloc) with a static variable structure that I would reuse. I did that for efficiency, since I found out that I was using the structure a lot, and I only needed one instance of the structure at any given time.
Well, I started to get kernel panics when passing the address of the structure to ctl_enqueuedata… solved by reverting back to a static pointer towards the OSMalloc'd structure...
Any idea on what's happening ?
Best regards,
Jean