473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

SIGSEGV in malloc()

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

May 7 '07 #1
5 6439
Joakim Hove said:

<snip>
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.
May 7 '07 #2
In article <kZ******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>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); }
Or (4) you've "run off the end" of some malloc()ed memory, perhaps
modfying the 5th element of a 4 element array. Any of these things
may mess up malloc()'s data structures, causing an obscure error some
time later when you call malloc() or free().

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
May 7 '07 #3
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); }

Or (4) you've "run off the end" of some malloc()ed memory, perhaps
modfying the 5th element of a 4 element array.
Thank you for the suggestion, it indeed turned out to be an error
along the these lines.
Any of these things
may mess up malloc()'s data structures, causing an obscure error some
time later when you call malloc() or free().
I guess what kind of baffled me (somewhat naively ??) was that it was
so easy to interfere with malloc()'s internal state. Anyway, now I
know.

Thank's again.

Joakim


May 7 '07 #4
In article <11**********************@o5g2000hsb.googlegroups. com>,
Joakim Hove <jo*********@gmail.comwrote:
>I guess what kind of baffled me (somewhat naively ??) was that it was
so easy to interfere with malloc()'s internal state. Anyway, now I
know.
There are many very effective tools that can help in tracking down
this kind of error. Valgrind for example has probably saved thousands
of person-years of tedious debugging.

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
May 7 '07 #5
On May 7, 11:05 pm, Joakim Hove <joakim.h...@gmail.comwrote:
>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); }
Or (4) you've "run off the end" of some malloc()ed memory, perhaps
modfying the 5th element of a 4 element array.

Thank you for the suggestion, it indeed turned out to be an error
along the these lines.

I guess what kind of baffled me (somewhat naively ??) was that it was
so easy to interfere with malloc()'s internal state. Anyway, now I
know.
Some people are extremely sensitive about the speed and
memory requirements of their programs that use malloc,
preferring that it use as few bytes and picoseconds of
overhead as possible, even if that means a fragile structure.

Accordingly, compilers tend to make their malloc as fast as
possible. However, some compilers offer a switch to use a
more robust allocation scheme during debugging (or even
in the release version, if the allocation is not a bottleneck);
check your compiler documentation.

May 7 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dieter Maurer | last post by:
Python 2.3.3, Linux 2.4.x: It looks as if a SIGSEGV in a thread of a multi threaded application does not kill the complete process under some circumstances but only one thread (unrelated to the...
0
by: Paffko | last post by:
What are the possibilities of getting SIGBUS and SIGSEGV errors in the following scenario? There is a program (C/C++/Pro*C) that was running fine under HP-UX 11.x and Oracle8i (8.1.6). Oracle...
7
by: USUN_TO | last post by:
Hi, i got problem when i bind in this way: local_addr.sin_family = AF_INET; local_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); local_addr.sin_port = htons(CLIENT_PORT); i can easly bind...
3
by: Patricia | last post by:
Hi, I ran my C++ application on UNIX and got the SIGSEGV: 11 error. dbx reads the core like below: 0x7f741f10: _malloc_unlocked+0x021c: ld , %o1 Current function is...
4
by: junky_fellow | last post by:
what is the difference between signals SIGBUS and SIGSEGV ? when does an application program receive SIGBUS and in which cases SIGSEGV ? thanx in advance for any help ...
3
by: Ralph A. Moritz | last post by:
Hi everyone, first of all, sorry for using Google to post. I know some people find this offensive, but as I am stuck behind a firewall, I don't have a choice. I am reading ``The Practice of...
13
by: vashwath | last post by:
Hi all, In my current project I am using signals for error handling. Since I cannot show full code, I have just shown important piece of code which is relevant. void sigsegenv() {...
0
by: Nancy | last post by:
Hi, I'm running 2.4 Python. I have an extension program that calls C funcs. Actually I have a C prog that calls python that calls C. In a python to C function call I get a SIGSEGV and this stack...
1
by: krazedkid | last post by:
I am trying to get my code to handle SIGSEGV multiple times, it will handle one of them but then nothing else. void sigHandler( int signum ) { if ( signum == SIGSEGV ) { printf("got a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.