[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: C programming: Segmentation fault within malloc?



Have you tried to look at the value sizeof(struct node)? It might be too big.
Otherwise, can you show us the backtrace in gdb.

On [Thu, 26 Jul 2001 03:15:46 +0300], Shaul Karl <shaulka@bezeqint.net> wrote:
> 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>
> 
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org 
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
> 

-- 
Shao Zhang                          Tel:  (02) 9209 4838
Software Engineer                   Fax:  (02) 9209 4992
Redfern Broadband Networks (RBN)    Mail: szhang@rbni.com



Reply to: