Memory Leak / Corruption

R

ranjeet.gupta

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
 
R

Richard Heathfield

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.
 
W

Walter Roberson

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.
 
J

junky_fellow

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.
 
F

Flash Gordon

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.
 
R

ranjeet.gupta

Flash said:
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.
 
F

Flash Gordon

(e-mail address removed) wrote:

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.
 
G

Gordon Burditt

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top