473,699 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random crashes

I have written an application in Visual C++ for a customer but it seems
to crash randomly.

Could anyone give me any help on how I could track this down ?

Also, there appears there might be memory leaks too. How can i track
these down ?

Jul 23 '05 #1
9 3848
gr**********@gm ail.com wrote:
Could anyone give me any help on how I could track this down ?


You ask to late: you should design your code to have not such errors
in the first place. The only thing I know which might help you now
is Purify: it highlights illegal accesses (e.g. out-of-bounds accesses,
reads to uninitialized memory, multiply released memory, memory leaks,
etc.).
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
<http://www.contendix.c om> - Software Development & Consulting

Jul 23 '05 #2
You are telling there is no application ever written that does not
crash from time to time ?

Just humour me a minute. Theoretically, how would you go about finding
out what is causing a random crash ?

Jul 23 '05 #3
gr**********@gm ail.com wrote:
You are telling there is no application ever written that does not
crash from time to time ?


If the application is controlling the communications of a spatial vehicle
orbiting Mars, it crash only one time ;)

--
Salu2
Jul 23 '05 #4

<gr**********@g mail.com> schrieb im Newsbeitrag
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
I have written an application in Visual C++ for a customer but it
seems
to crash randomly.

Could anyone give me any help on how I could track this down ?

Also, there appears there might be memory leaks too. How can i track
these down ?


I bet's it's something like:
int a[5]; a[7] = 13;

-Genrot
Jul 23 '05 #5

<gr**********@g mail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
I have written an application in Visual C++ for a customer but it seems
to crash randomly.

Could anyone give me any help on how I could track this down ?

Also, there appears there might be memory leaks too. How can i track
these down ?


It's quite likely that the two are related. I would assume that you're
using new and delete in variaous places, as that is the easiest way to get
memory leaks, It's also an opening for crashes, if you don't handle your
pointers correctly. Look carefully in your code for everywhere you use
pointers. Memory leaks exist where pointers are newed but never deleted.
Also, anywhere you have a new[], you need a matching delete[], not just
delete.

Run your code in a debugger. It may not crash there, but it will help you
spot any place where you access an invalid pointer.

Look especially for use of pointers that have not had an object assigned to
them yet. These are called "uninitiali zed pointers", and are often the
problem if you've got code that didn't crash in a debug build but does in
release builds. That's especially true if you've got checks in the code for
testing if a pointer is NULL. In debug builds, the memory may get zeroed
out, so that uninitialized pointers test as NULL, but in the release buidls,
the memory is not zeroed out in advance, so the pointer contains garbage,
and your test for NULL fails. Make sure all pointers point to valid data or
are set to NULL when defined.

The other main memory issue that causes random crashes is overrunning the
end of an array. You may have forgotten to leave enough space for the null
terminator in a C-style string (char array). Or you may have a loop that
indexes the array starting at 1 instead of 0. In those cases, when you
write past the end of the array, you stomp on some other part of memory,
which may belong to code that executes an hour later, causing the "random"
crash.

Hope this helps...

-Howard


Jul 23 '05 #6
gr**********@gm ail.com wrote:

You are telling there is no application ever written that does not
crash from time to time ?
He didn't tell you that.
All Dietmar said, is: If the application is designed right, the
likelyhood of crashes decreases. And if it crashes, then the programmer
most often knows what to do :-)

Just humour me a minute. Theoretically, how would you go about finding
out what is causing a random crash ?


The first thing that needs to be done:
Transform 'random crash' into:
'It crashes, if it does x, followed by y, followed by z.'

in other words: make the crashes deterministic or at least figure
out where the crash happens and what subsystems of the program are
involved. This might require you to write a logfile and carefull
study of that logfile to figure out what is going on. Once you know
where the crash happens and know what was involved with the crash, the
real fun begins: 'figuring out why it crashed'.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 23 '05 #7
greenings...@gm ail.com wrote:
You are telling there is no application ever written that does not
crash from time to time ?
No, I don't. However, it is quite long since I had random crashes in
my own programs (except for some MT errors...): I either had blatant
errors which just crashed the program as soon as the code was executed
or the applications just run.
Just humour me a minute. Theoretically, how would you go about finding out what is causing a random crash ?


I actually already said how I would go about finding random crashes:
run the program with Purify. OK, that was before I checked the prices
(something like EUR 3000 and above...): this does not necessarily make
it a viable tool in all cases :-( However, it is definitely worth its
price for professional software development using C or C++: I'm using
this tool to verify the correctness of my programs (and it very rarely
detects anything) and to correct errors in programs, including ones
I haven't written. If you are not used to using Purify, it almost
certainl will highlight questionable program segments. Some of these
are actually false positives but these are easily suppressed (typical
suppression files I have include one or two dozens entries, often
duplicates due to different software versions). In general, Purify
only shows problems. You can get an evaluation version from IBM's site.

Assuming that Purify is no option due to its steep price, there are
a few other things you may be able to do:

- For the off-chance that the random crashes are actually a genuine
error caused at the crash site, you should load a core into your
debugger and analyse the code section for problems. If the random
errors are indeed random, this will not have much effect, however.

- Compilers are relatively smart about what a programmer should better
not do. Thus, you should compile your program with highest warning
level and act on each warning! The action may be a comment in the
code ("compiler warns about ... but this is actually OK") after
verifying that the code indeed does with it is supposed to do. Like
with Purify, compilers also give false positives and may force you
into a slightly different programming style to make the warnings go
away but often they are right about their complaints.

- Repeat the previous step with a different compiler! Actually, trying
to compile and run your code with a different compiler may provide
you with unexpected behavior already. Also, different compilers
enforce different rules, i.e. you should even expect compiler errors
when using a different compiler which also highlight problematic
section - at least often. Sometimes they are also due to inferior
compliance to the C++ standard, i.e. you probably want to use are
rather compliant compiler (e.g. Comeau C++ for just $50 is an
option).

This is mostly about static analysis and there are even programs
which specialize in static analysis e.g. from Gimpel (PCLint) and
Programming Research (QAC++). However, these tools also have a
rather non-negligible price.

- Search for uses of "known" dangerous functions, e.g. 'gets()',
'sprintf()', 'operator>>(cha r*)', etc. Where possibly, replace
them with safe alternatives (e.g. 'fgets()', 'snprintf()',
'operator>>(std ::string)') and in all other places verify that
they cannot cause any problems, e.g. because the input is already
known and verified.

OK, this far the stuff is rather non-intrusive: the application is
not changed in any form specifically for testing (handling warnings
and errors may incur changes but these will stay in the code). If
this did not yield sufficient results or if you want to do further
verification, you would create a special test version of your
application:

- Some libraries, including standard libraries, come with debugging
versions or you can obtain some debugging version. For example,
you can using STLPort in debugging mode as a replacement for [most
of] the standard C++ library. In debugging mode this library will
test many things which a release version version does not test,
e.g. out of bound access in 'std::vector'. Run your application
after compiling it with the most aggressive debugging options
turned on.

- Some compilers have switches which will result in the memory of
released variables being overwritten by some fixed bit pattern.
Often you can replace the memory management functions ('malloc()',
'free()', 'operator new()', etc.) to do something similar. This
detects uses of stale objects.

- Again replacing the memory management functions, you can arrange
for memory blocks being located at page boundaries where the
adjacent page is access protected - at least if you are not
using lots of memory. efence is a library which does just that.

If nothing of the above helps, its time to purchase Purify... If
this is not an option, it is time to rework the whole application to
use modern C++ techniques, e.g. containers, smart pointers, etc.
These make some problem detection viable through libraries like
STLport. Of course, this get rather involved. If you are going down
this route, here are more things you might want to consider:

- Single step through the program and verify that the "right" thing
is happening. It is sometimes quite surprising that the program
does other things than you might expect.

- Do a thorough code review.

The important thing to note is that I'm not really making fun of you
if I state that you should have programmed your application
differently from ground up: some techniques lend to better error
discovery than others. Following certain styles, using certain
libraries, etc. helps with program correctness. It actually helps
that much that even in C++ "typical" programming errors like the
"random crash" can be prevented most of the time. The areas where
this can not [yet] be done seem to lack appropriate approaches, e.g.
multi-threading.
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
<http://www.contendix.c om> - Software Development & Consulting

Jul 23 '05 #8
Hi,

You can check whether you are deleting an object that has already
being deleted.

Or you can use memory manager http://www.fluidstudios.com/?freeware
to detect memory leak

ko*****@w-manager.com

Jul 23 '05 #9
gr**********@gm ail.com wrote:
You are telling there is no application ever written that does not
crash from time to time ?

Just humour me a minute. Theoretically, how would you go about finding
out what is causing a random crash ?


This is really outside the realm of the language you are using, but what
you need to learn about is post-mortem analysis. On Unix (which I am
more familiar with), when a program crashes it leaves a file called
'core' (or sometimes 'core.pid'). This file can be loaded with a
debugger and will show you the state of the process when it crashed.
Depending on what exactly caused the crash, you may be able to see the
specific cause of the crash (for example, trying to dereference a NULL
pointer). Hopefully you can then go from specific cause to root cause
(why did you program logic allow a NULL pointer at that place).

Unfortunately, not all crashes can easily be solved via post mortem
debugging. If memory gets trashed, by the time the program actually
crashes it can be extremely difficult to work out the root cause.

That said, on Windows there is some way to configure it to leave the
equivalent of a core called a user.dmp; you'll need to configure
DrWatson correctly to have one generated on crash.

samuel
Jul 23 '05 #10

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

Similar topics

7
364
by: Steve D. | last post by:
I recently installed VS.NET 2003 After opening a project and leaving it open, after a certain period of time it crashes. It only does this when a project is open. The project that I've tried this with is *very* small and simple. One of the boxes that are displayed as part of the crashes references "devenv.exe" (the Visual Studio IDE executable). I've tried uninstall/reinstall. I have the latest .NET Framework SDK.
5
2307
by: Rob Ristroph | last post by:
Hi, It's pretty unhelpful to post "I have a huge piece of code that crashes in strange places, what's the problem?" but that's basically my problem and I really am at my wit's end. The piece of code in question always crashes in an STL operation such as a vector.push_back, but the location of the crash changes as I change how various parts are handled in memory, i.e., make some things dynamically allocated instead of new'd. I know...
8
15297
by: Gary Joy | last post by:
I really am banging my head with this one... I have a regular unmanaged C++ application that is using mixed DLLs to (amongst other things) call a C# back-end (which is using ADO .NET). I am getting random crashes, typically after 15-60 minutes of inactivity. The error message and call stack are listed below. Unhandled exception at 0x792483e0 (mscorwks.dll) in debug_build_wks_crash.dmp: 0xC0000005: Access violation reading location...
8
1800
by: Lars-Erik Aabech | last post by:
Hi! We've got an ASP.NET application that runs swell on development PC's and one live production server. Another prod. server though crashes a couple of times a week. Either something that should be bound reports that column X isn't found, or that the IListSource does not contain any datasources. We get the solution up again by restarting aspnet_wp. This may happen if aspnet_wp is at 40 mb or 400mb, so it's not memory related. The SQL...
4
4780
by: Jared Kitcher via .NET 247 | last post by:
I am working on a .Net project and our application randomlycrashes with no exception being thrown. The application justdisappears, like someone would have clicked the exit button. This occurs both when we are debugging and when the applicationis running after an install. I have been stepping through codeand then just had the application stop and VS just goes back tonormal, like I had told it to exit the code. I have read abouta couple of other...
0
1052
by: Mathias Waack | last post by:
Hi all, I've embedded python into an older application and created some extensions to interact with the old data structures. Everythings works like a charm - beside a simple "import random". During import the whole process crashes with a SIGILL. I've found some older mails describing just the same problem: http://mail.python.org/pipermail/python-dev/2003-May/035386.html Unfortunately I'm not able to read x86 assembler code:( I'm using...
3
1646
by: hande | last post by:
Hi, I wrote a program with two threads playing a number guessing game. one thread pick a number the other try to guess it. Also first thread say try a lower or higher number. but my program crashes in defining the bounds for generating random numbers. For instance the first thread pick 35 the other say 19. he should pick a number bigger than 19. for now that's ok. now second thread say 60. then first thread say lower number. but my second...
1
4597
by: Pucca | last post by:
I'm getting the follow error message randomly and then my application crashes. How can I locate the bug code and how can I fix this? Managed Debugging Assistant 'DisconnectedContext' has detected a problem in 'C:\Projects\UnityAdmin\bin\Release\UnityAdmin.vshost.exe'. Additional Information: Context 0x18fac8' is disconnected. Releasing the interfaces from the current context (context 0x18f978).This may cause corruption or data loss. To...
3
3881
by: John Fairhurst | last post by:
Hi, The following code should select the specified number of records randomly from the database <% .... query = "SELECT FROM " Set RS = Server.CreateObject("ADODB.Recordset")
0
8615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8911
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7748
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6533
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.