C programming: Segmentation fault within malloc?
Breakpoint 2, insert_symbol (sym=0xbfffe25c) at symbols.c:197
197 if (!((node = (struct node *)malloc(sizeof(struct node))) &&
(gdb) l 197
192
193 enum flag insert_symbol(struct symbol *sym)
194 {
195 struct node *node;
196
197 if (!((node = (struct node *)malloc(sizeof(struct node))) &&
198 (node->data = (struct symbol *)malloc(sizeof(struct
symbol))))) {
199 fprintf(stderr, sym_tab_msg[MEMORY_ALLOCATION_FAILURE]);
200 return FALSE;
201 }
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
0x400af19e in malloc () from /lib/libc.so.6
(gdb)
How can it be? If malloc can not allocate memory it should return a NULL
pointer. How can it Seg fault?
[03:09:45 16]$ free
total used free shared buffers cached
Mem: 63584 60936 2648 31452 1344 20472
-/+ buffers/cache: 39120 24464
Swap: 116924 52580 64344
[03:09:49 16]$
Since all the memory is used and the machine is running for some time now,
doesn't that precludes hardware problems?
Obviously I am missing something.
--
Shaul Karl <shaulka@bezeqint.net>
Reply to: