473,554 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Memory Leak / Corruption

Dear All

Is the Root Cause of the Memory corruption is the Memory leak, ??
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?

In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.

Juts Theoritical Assumtion below:

Ideally Memory leak, may not lead to the Memory Corruption.
Here I am talking, if Memory leak Is accepted.

Thnaks In Advance.
Ranjeet

Nov 15 '05 #1
8 3394
In article <11************ **********@f14g 2000cwb.googleg roups.com>,
<ra***********@ gmail.com> wrote:
Is the Root Cause of the Memory corruption is the Memory leak, ??
No, almost never.
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?
No.
In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.


Memory corruption is usually writing into memory you do not
own. That might be because you ran over the beginning
or end of an array, or because you free()'d an already
free()'d pointer, or because you used a pointer that
you did not initialize, or because you had an incompatability
with parameter passing and are taking non-pointer data
and treating it as a pointer, or it could be from trying
to write through a NULL pointer... or through other methods
involving various undefined or prohibitted pointer behaviours.

When you have memory corruption, it is common that you corrupt
the information that the system is using to keep track of
allocated memory. That corruption might not show up immediately,
but if you have a memory leak then sooner or later that internal
information is likely to be needed -- whereas without a memory
leak, you just might not happen to read that portion of memory.

There is not, in other words, a strong connection between
memory leaks and memory corruption.

There is, though, a fairly strong connection between memory
leaks, running out of memory (because it all leaked away),
and not having been careful to check the result of every
memory allocation, and thus ending up with a NULL pointer that
one thought was initialized.

--
"[...] it's all part of one's right to be publicly stupid." -- Dave Smey
Nov 15 '05 #2
ra***********@g mail.com wrote:
Dear All

Is the Root Cause of the Memory corruption is the Memory leak, ??
No.
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?
No.

In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.


A memory leak is when you no longer remember where memory you own is
located. This is very silly. Memory corruption is when you refer to memory
you don't own. This is even sillier.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain
Nov 15 '05 #3

ra***********@g mail.com wrote:
Dear All

Is the Root Cause of the Memory corruption is the Memory leak, ??
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?

In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.

Juts Theoritical Assumtion below:

Ideally Memory leak, may not lead to the Memory Corruption.
Here I am talking, if Memory leak Is accepted.

Memory leak is a bug in your program where the memory is allocated
but not freed afterwards although it is never used again.
It has nothing to do with memory corruption.
It should be avoided otherwise your program would grab and more
memory diminishing the performance.

Nov 15 '05 #4
ra***********@g mail.com wrote:
Dear All

Is the Root Cause of the Memory corruption is the Memory leak, ??
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?

In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.

Juts Theoritical Assumtion below:

Ideally Memory leak, may not lead to the Memory Corruption.
Here I am talking, if Memory leak Is accepted.


Memory leaks and memory corruption are completely different things. A
memory leak is loosing track of some memory you own, memory corruption
is overwriting memory you should not which might be owned by your
process or some other processs.

Imagine you are putting all of your stuff in to storage.

A memory leak is where you forget where one of the boxes is. The box
still exists, whatever it contains is still in it, but you can't get at
it because you don't know where it is (have no pointer to it).

Memory corruption is where you put so much in one box that it overflows
The overflow might land somewhere unused, in which case everything seems
OK at first sight, or it might spill over on to property owned by a
Mafia boss, in which case someone might come round and break your legs,
or it might spill over on to some priceless and extremely delicate
porcelain smashing it to pieces.
-
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #5

Flash Gordon wrote:
ra***********@g mail.com wrote:
Dear All

Is the Root Cause of the Memory corruption is the Memory leak, ??
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?

In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.

Juts Theoritical Assumtion below:

Ideally Memory leak, may not lead to the Memory Corruption.
Here I am talking, if Memory leak Is accepted.
Memory leaks and memory corruption are completely different things. A
memory leak is loosing track of some memory you own, memory corruption
is overwriting memory you should not which might be owned by your
process or some other processs.

Imagine you are putting all of your stuff in to storage.

A memory leak is where you forget where one of the boxes is. The box
still exists, whatever it contains is still in it, but you can't get at
it because you don't know where it is (have no pointer to it).

Memory corruption is where you put so much in one box that it overflows
The overflow might land somewhere unused, in which case everything seems
OK at first sight, or it might spill over on to property owned by a
Mafia boss, in which case someone might come round and break your legs,
or it might spill over on to some priceless and extremely delicate
porcelain smashing it to pieces.
-


So guys dont you all think, assume if there is total memory leak,
And it leads to the finishing off the memroy, and then it may lead
to the Memory corruption.

Looks to me that if you dont have enough memory through the Memory
leaks
then it might be possible due to unavailbility of the memory, memory
corruption may occur.

Note:
Just I am trying to correlate the case between the Memory leak
and memory corruption. Above might be one situation.

Flash Gordon:

I am really very affraid of Mafia Boss, So I mostly Pick all my
belongings vaccate the place before I leave for outing. :-)
I do follow the Cleaning of memories as soon it is done.
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.


Nov 15 '05 #6
ra***********@g mail.com wrote:

<snip>
So guys dont you all think, assume if there is total memory leak,
And it leads to the finishing off the memroy, and then it may lead
to the Memory corruption.
Why would it?
Looks to me that if you dont have enough memory through the Memory
leaks
then it might be possible due to unavailbility of the memory, memory
corruption may occur.
No, or at least not directly. If you fail to check the return value of
malloc and friends then you might try to write through a null pointer
which could corrupt something, but on a lot of systems it will just lead
to an immediate crash.
Note:
Just I am trying to correlate the case between the Memory leak
and memory corruption. Above might be one situation.


The only correlation in general is that programmers who write software
with memory leaks are likely to also make other mistakes.

Memory corruption is generally caused by overrunning buffers, using
memory after it has been freed and double freeing. I've never come
across memory being corrupted because a process ran out of memory.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #7
>Is the Root Cause of the Memory corruption is the Memory leak, ??

No, because the program needs to do something wrong other than leak
memory to lead to memory corruption. One such thing is failure to
check for a NULL return from malloc() before trying to use the
memory. (Memory leaks MAY cause malloc() to return NULL when it
otherwise wouldn't have.) Another is to use more memory than what
was actually allocated (array subscript out of bounds), but that
has nothing to do with leaks.
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?
Only if the program does something else wrong/stupid. Arguably,
being born may lead to memory leaks because you might later learn
C, and write code after learning C, and it might contain a memory
leak. But I wouldn't claim that being born causes memory leaks.
In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.
They are not married to each other. They usually aren't related at all.
About the only relation comes when a memory leak causes malloc() to
return NULL, and the program also fails to check whether malloc()
succeeded (THIS is the root cause, not the leak) and corrupts memory
because of that.
Juts Theoritical Assumtion below:

Ideally Memory leak, may not lead to the Memory Corruption.
Here I am talking, if Memory leak Is accepted.


Memory leaks are not accepted as currency anywhere I have ever
heard of. What do you mean by "accepted" in this context?

Gordon L. Burditt
Nov 15 '05 #8
Mac
On Thu, 18 Aug 2005 23:29:23 -0700, junky_fellow wrote:

ra***********@g mail.com wrote:
Dear All

Is the Root Cause of the Memory corruption is the Memory leak, ??
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?

In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.

Juts Theoritical Assumtion below:

Ideally Memory leak, may not lead to the Memory Corruption.
Here I am talking, if Memory leak Is accepted.

Memory leak is a bug in your program where the memory is allocated
but not freed afterwards although it is never used again.
It has nothing to do with memory corruption.
It should be avoided otherwise your program would grab and more
memory diminishing the performance.


Well, I think a memory leak is best defined as repeatedly allocating
memory then losing track of where it is (so that it cannot be used or
freed).

If you allocate some memory once, don't lose track of it, and rely on
the OS to reclaim the memory when the process terminates, that is arguably
NOT a memory leak.

--Mac

Nov 15 '05 #9

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

Similar topics

5
4859
by: blugus | last post by:
Hi Guys, I've been try to use Dinkum STL library. It workes well first, but report memory leak in MFC Debug Mode. I use Dinkum Unabridged Library for VC++ V4.02, MSVC6, WIN2000 SERVER. I made a dialog based program by MSVC6, inserted simple code to use Dinkum STL Library, and added simple code like this.
5
307
by: RoSsIaCrIiLoIA | last post by:
why not to build a malloc_m() and a free_m() that *check* (if memory_debug=1) if 1) there are some errors in bounds of *all* allocated arrays from them (and trace-print the path of code that make the error and exit) just when malloc_m and free_m start. (I use a 1100 static array for write the path (like a queue) of called function, operator,...
10
14027
by: eyh5 | last post by:
Hi, My C code (running on Soalris Unix) has some "segmentation fault" that I wish to use purify to do it. I poked around the web, and found some information about adding some lines in a Makefile file to use purify. However, my code is a rather simple single-source C program, and I didn't write a Makefile for it. I'm wondering if anybody...
4
2786
by: Tomassus | last post by:
Hi there, I have a problem with dynamic memory allocation. I know that it would have been easier to use vectors methods, but i want to know what i do here wrong. This is one of my methods in t_Item class - I use it to store Item Objects (which are classes too). xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx class t_Item { public:
3
2913
by: talefsa | last post by:
Hi, I'm trying to figure out the origin of a memory corruption in my code using valgrind. valgrind gave me a number of messages that didn't help much, the first invalid read/write message is as follow: ==22774== Invalid write of size 4 ==22774== at 0x488F53A: std::string::_Alloc_hider::_Alloc_hider(char*, std::allocator<char> const&)...
9
9215
by: Bruno Barberi Gnecco | last post by:
I'm using PHP to run a CLI application. It's a script run by cron that parses some HTML files (with DOM XML), and I ended up using PHP to integrate with the rest of the code that already runs the website. The problem is: it's eating more memory than a black hole. It eats the current limit of 256MB set in php.ini, in an application that would...
16
1660
by: KG | last post by:
Hi, I do have a question. int main() { char *p = (char *)malloc(9); strcpy(p,"TajMahal"); p++;
6
5555
by: nmehring | last post by:
I have an MFC app with 2000 users. I have one user that experiences a crash in our software anywhere from 1 to 5 times a week when opening a particular module. No other users have reported this particular crash so I don't think anyone else is experiencing it but I know other users are doing exactly what she is doing because it is our most...
6
2078
by: ashjas | last post by:
Hello all.. I am experiencing memory leakes in on of my applications that i am developing. the % of memory used for the application is increasing as shown in the top command on linux. The memory is leaking only when a function is called where i am allocating memory dynamically to a pointer(char string,i,e c-string). if i replace the...
0
7581
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8018
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7872
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...
0
6123
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...
1
5423
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...
0
3545
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...
0
3533
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2006
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
1
1114
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.