By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,103 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

Memory Leak / Corruption

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
In article <11**********************@f14g2000cwb.googlegroups .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

P: n/a
ra***********@gmail.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

P: n/a

ra***********@gmail.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

P: n/a
ra***********@gmail.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

P: n/a

Flash Gordon wrote:
ra***********@gmail.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

P: n/a
ra***********@gmail.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

P: n/a
>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

P: n/a
Mac
On Thu, 18 Aug 2005 23:29:23 -0700, junky_fellow wrote:

ra***********@gmail.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 discussion thread is closed

Replies have been disabled for this discussion.