472,780 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

catching unexpected segmentation fault and performing cleanup

Hi, sometimes due to unchecked code I get segmentation faults once in a
while and would like to be able to catch them and do some cleanup on
things. This segmentation fault could be anywhere in the code.

Could it be caught like a signal and perform cleanup then? Or would I
have to put every piece of function code in try and catch blocks?

Thanks
Ankur

Aug 15 '06 #1
6 5089
g3******@gmail.com wrote:
Hi, sometimes due to unchecked code I get segmentation faults once in a
while and would like to be able to catch them and do some cleanup on
things. This segmentation fault could be anywhere in the code.

Could it be caught like a signal and perform cleanup then? Or would I
have to put every piece of function code in try and catch blocks?
On a typical (that is all those I'm aware of!) environment, you can't
catch a segmentation/memory access fault except while running under a
debugger or emulator.

Fix your code.

--
Ian Collins.
Aug 15 '06 #2
On Tue, 15 Aug 2006 18:17:23 +1200, Ian Collins <ia******@hotmail.com>
wrote:
>g3******@gmail.com wrote:
>Hi, sometimes due to unchecked code I get segmentation faults once in a
while and would like to be able to catch them and do some cleanup on
things. This segmentation fault could be anywhere in the code.

Could it be caught like a signal and perform cleanup then? Or would I
have to put every piece of function code in try and catch blocks?
On a typical (that is all those I'm aware of!) environment, you can't
catch a segmentation/memory access fault except while running under a
debugger or emulator.
It is possible to catch SIGSEGV/SIGBUS on Solaris.
>Fix your code.
Agreed.

Mark

Aug 15 '06 #3

Mark wrote:
On Tue, 15 Aug 2006 18:17:23 +1200, Ian Collins <ia******@hotmail.com>
wrote:
g3******@gmail.com wrote:
Hi, sometimes due to unchecked code I get segmentation faults once in a
while and would like to be able to catch them and do some cleanup on
things. This segmentation fault could be anywhere in the code.

Could it be caught like a signal and perform cleanup then? Or would I
have to put every piece of function code in try and catch blocks?
On a typical (that is all those I'm aware of!) environment, you can't
catch a segmentation/memory access fault except while running under a
debugger or emulator.

It is possible to catch SIGSEGV/SIGBUS on Solaris.
Sorry I forgot to specify I am on Linux RH9 and FC5
Fix your code.

Agreed.
What if it is caused by someone else's program? or library that you
have no control over, or if you are doing a client server program with
defined rules and the client breaks the rules?
Mark
Aug 15 '06 #4
g3******@gmail.com wrote:
Mark wrote:
On Tue, 15 Aug 2006 18:17:23 +1200, Ian Collins <ia******@hotmail.com>
wrote:
>g3******@gmail.com wrote:
>Hi, sometimes due to unchecked code I get segmentation faults once in a
>while and would like to be able to catch them and do some cleanup on
>things. This segmentation fault could be anywhere in the code.
>>
>Could it be caught like a signal and perform cleanup then? Or would I
>have to put every piece of function code in try and catch blocks?
>>
>On a typical (that is all those I'm aware of!) environment, you can't
>catch a segmentation/memory access fault except while running under a
>debugger or emulator.
It is possible to catch SIGSEGV/SIGBUS on Solaris.

Sorry I forgot to specify I am on Linux RH9 and FC5
>Fix your code.
Agreed.

What if it is caused by someone else's program? or library that you
have no control over, or if you are doing a client server program with
defined rules and the client breaks the rules?
On some platforms you can do it (e.g., use signal handlers on most UNIX
platforms or __try/__except/__finally with VC++), but there is no
standard way. Ask in a newsgroup for your platform or compiler (cf. the
list at
http://www.parashift.com/c++-faq-lit....html#faq-5.9).

Cheers! --MM

Aug 15 '06 #5

g3******@gmail.com wrote:
Mark wrote:
It is possible to catch SIGSEGV/SIGBUS on Solaris.

Sorry I forgot to specify I am on Linux RH9 and FC5
>Fix your code.
Agreed.

What if it is caused by someone else's program? or library that you
have no control over, or if you are doing a client server program with
defined rules and the client breaks the rules?
The first should never happen.

The second you can't do anything about.

The last, your server program should never trust client code...plain
and simple. Don't access memory based on input from an external,
untrusted source.

Aug 15 '06 #6

"mlimber" <ml*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
g3******@gmail.com wrote:
On some platforms you can do it (e.g., use signal handlers on most UNIX
platforms or __try/__except/__finally with VC++), but there is no
standard way. Ask in a newsgroup for your platform or compiler (cf. the
list at

in Visual C++ you can catch invalid memory access using a normal try-catch.
But you need to compile your code using the /EHa option.
There is also a callback which you can set to throw your own type of
exception.
This callback must be set using _set_se_translator.
Otherwise catch(...) must be used.

Aug 16 '06 #7

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

Similar topics

15
by: Dennis Schulz | last post by:
hi y'all im a beginner in C language and i have problems running this programm. when i enter a newline there is a "segmentation fault". i dont know what it means and already spent too much time...
3
by: Zheng Da | last post by:
Program received signal SIGSEGV, Segmentation fault. 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 #1 0x40094c54 in malloc...
5
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
7
by: pycraze | last post by:
I would like to ask a question. How do one handle the exception due to Segmentation fault due to Python ? Our bit operations and arithmetic manipulations are written in C and to some of our...
3
by: madunix | last post by:
My Server is suffering bad lag (High Utlization) I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2 Web visitors retrieve data from the web by php calls through oci cobnnection...
6
by: DanielJohnson | last post by:
int main() { printf("\n Hello World"); main; return 0; } This program terminate just after one loop while the second program goes on infinitely untill segmentation fault (core dumped) on...
2
by: Verdana | last post by:
We're using Python 2.5 on our production and testing servers, which both run SunOS 5.8 and Oracle 10g. The script we're working on is supposed to process wddx packets, enter some info in the database...
10
by: H.S. | last post by:
Hello, I have class in which I am allocating space for a double array in the constructor. I use the double array twice in one of the methods and then delete that array in the class's destructor....
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.