Reputation: 401
Could someone please explain this error? It craps out when I try to free the array. It works fine when I malloc inside of main so I'm guessing its because of the function scope? I thought if I return the pointer to the malloc then it wouldn't matter where I try to free it.
Thread 1 received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffd80a5719f in ntdll!RtlRegisterSecureMemoryCacheCallback () from C:\Windows\SYSTEM32\ntdll.dll
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
typedef struct array { int length; int size; void *data; } array;
static array* new(int length, int size)
{
array *array = malloc(sizeof(array));
array->length = length;
array->size = size;
array->data = malloc(length * size);
return array;
}
int main()
{
array *a = new(5, sizeof(int));
free(a->data);
free(a); // debugger points me to here
return 0;
}
Upvotes: 2
Views: 53