![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 4
| There is a nasty segfault in my code that keeps pestering me. The error is probably buried deeply in my beastly sized code so I won't post it and ask you to deal with it, but I just want to know when this simple code... Code: int* value_ptr = (int*) malloc (sizeof (int)); My idea would be never, but still it does. (Oh, and yes apart from 'return 0' in main, this is the last line of my code.) Any help would be appreciated. Output of gdb: Code: Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7b011e6 in _int_malloc () from /lib/libc.so.6 Last edited by Driehoek; 10-28-2009 at 07:11 PM. Reason: Added debuging output. |
| Driehoek is offline | |
| | #2 |
| Registered User Join Date: Oct 2009
Posts: 4
| Upon further investigation, all calls to malloc segfault. I did something weird somewhere. |
| Driehoek is offline | |
| | #3 |
| Registered User Join Date: Oct 2009
Posts: 4
| I'm double freeing a pointer somewhere, that must be the problem. |
| Driehoek is offline | |
| | #4 |
| Registered User Join Date: Sep 2007
Posts: 372
| If it supports your platform, give Valgrind a try. It can catch memory problems very early, so if you overwrite malloc()'s internal housekeeping, double free, etc, it will tell you right then and there. You don't have to wait till the problem manifests itself during a later call to malloc() leaving you to guess where the corruption happened. |
| cas is offline | |
| | #5 |
| Registered User Join Date: Oct 2009 Location: Indonesia
Posts: 60
| yeah.. same like me, malloc doesn't identified in my compiler.. (I use visual C) is there someone can explain me? |
| Kinshara is offline | |
| | #6 |
| Registered User Join Date: Oct 2009
Posts: 4
| Thanks for advising Valgrind too me Cas. I forgot about it, I solved my problem with it. |
| Driehoek is offline | |
![]() |
| Tags |
| malloc, pointer, segfault, segmentation fault |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| weird things with my linked list of queue | -EquinoX- | C Programming | 3 | 11-22-2008 11:23 PM |
| malloc() resulting in a SegFault?! | cipher82 | C++ Programming | 21 | 09-18-2008 11:24 AM |
| use of printf prevents segfault! | MK27 | C Programming | 31 | 08-27-2008 12:38 PM |
| Weird fopen() segfault | faffi | C Programming | 10 | 03-05-2008 12:48 PM |
| weird segfault in fgets in process | 911help | C Programming | 10 | 12-29-2007 01:51 PM |