C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SIGSEGV in malloc()

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language
View previous topic :: View next topic  
Author Message
Joakim Hove
Guest





PostPosted: Mon May 07, 2007 9:12 am    Post subject: SIGSEGV in malloc() Reply with quote



Hello,

in my application I have a typedefed struct:

typedef struct {
double d1;
int i1;
/* I have simplified the object here. */
} data_ptr_type;


I allocate storage for such object many times in my application, and
at some point in time (repeatedly at the same spot, but seemingly
random to me), the application fails with a SIGSEGV at:

data_ptr_type * data = malloc(sizeof *data);

To me it seems quite illogical that the malloc implementation should
be able to die with a SIGSEGV(?) - either it should return a pointer
to freshly allocated storage, or if that is not possible it should
return NULL. Can this be a sign of a bug in the malloc()
implementation - I know that sounds unlikely but??

My system is:
RedHat Enterprise Linux
gcc-3.4.6
64 bit computer, but comiled with -m32 switch.

Any suggestions?

Regards Joakim
Back to top
Richard Heathfield
Guest





PostPosted: Mon May 07, 2007 9:12 am    Post subject: Re: SIGSEGV in malloc() Reply with quote



Joakim Hove said:

<snip>

Quote:
I allocate storage for such object many times in my application, and
at some point in time (repeatedly at the same spot, but seemingly
random to me), the application fails with a SIGSEGV at:

data_ptr_type * data = malloc(sizeof *data);

To me it seems quite illogical that the malloc implementation should
be able to die with a SIGSEGV(?) -

It's impossible to say for sure without seeing the code, but it's my
guess that you've probably done one of these three things:

1) free(p); ..... later, you used this indeterminate pointer value - OR
2) free(p); ..... later, free(p); - OR
3) p = malloc(sizeof *p); if(p != NULL) { modify(&p) somehow; free(p); }

Like I said, I'm just guessing really (because I can't see the code),
but any of the above could explain why your malloc arena is stuffed.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.