//This LOOKED like it worked but failed when trying to free()
int *ptr = (int *) malloc(sizeof(int));
int x = 42;
ptr = &x;
free(ptr);
//This is what I meant to do in the first place
int *ptr = (int *) malloc(sizeof(int));
int x = 42;
*ptr = x;
free(ptr);