I am trying to dynamically allocate memory for some integers and am getting a segfault. This code runs fine on native MacOS, but fails when I try to run it on my Ubuntu virtual machine? What's the difference?
Code
// Create stuff to add
int* a = malloc(sizeof(int));
int* b = malloc(sizeof(int));
int* c = malloc(sizeof(int));
int* d = malloc(sizeof(int));
*a = 0;
*b = 1;
*c = 2;
*d = 3;
Error
Breakpoint 1, test_add_4_and_check () at test.c:125
125 int* a = malloc(sizeof(int));
(gdb) n
126 int* b = malloc(sizeof(int));
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7a8b48a in malloc_consolidate (
av=av@entry=0x7ffff7dd1b20 <main_arena>) at malloc.c:4175
4175 malloc.c: No such file or directory.