Recently met a problem, when developing a DLL, in which the malloc () the memory, but when access the access violation, want to consult everybody bosses may be the reasons for this?
DLLEXT long AMI_Init (void * * AMI_dll_memory)
{
Mem=(struct model_memory *) malloc (sizeof (struct model_memory));
Mem - & gt; Submem=(struct submem *) malloc (sizeof (struct submem));
.
* AMI_dll_memory=(void *) mem;
}
DLLEXT long AMI_Get (void * AMI_dll_memory)
{
.
AMI_dll_memory mem=(struct model_memory *);
Mem - & gt; Submem - & gt; init();
}
//Defined in submem module
Struct {
The int data;
Struct list * next;
} the list;
Void init ()
{
Struct list * n.
N=(struct list *) malloc (sizeof (struct list));
//access n - & gt; The data under caused the memory access violation.
}
DLL will be other programs call, the first is to call AMI_Init () to initialize the part of memory, and memory of the first address AMI_dll_memory passed to the parameters, and then invokes the AMI_Get (), then I'm AMI_Get () in the init () function on the malloc (), a new node direct access violation, but here I don't understand is why, want to consult everybody who is this why? I'm sure this list n nodes malloc () is successful, but when I try to access, access violation, very thank you for your comment,
CodePudding user response:
Debugging, whether n is empty?CodePudding user response:
C the Run - Time Libraries https://msdn.microsoft.com/en-us/library/abx4dbyh.aspxCodePudding user response: