473,910 Members | 4,512 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 3426
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
4873
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, etc and write using '+' where is find the memory error) 2) if the pointer to free is alredy...
10
14073
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 can tell me which commands are to be entered at the Unix prompt to use purify. And, I don't know if...
4
2800
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
2934
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&) (in /usr/lib/libstdc++.so.5.0.3) ==22774== by 0x488FC26: std::string::string(char const*,...
9
9233
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 hardly consume 4MB if written in C. I don't care if this application takes much longer to run...
16
1691
by: KG | last post by:
Hi, I do have a question. int main() { char *p = (char *)malloc(9); strcpy(p,"TajMahal"); p++;
6
5590
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 popular module. I have analyzed the dmp files from several of this user's crashes using windbg...
6
2096
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 logic with the use of stl string the memory leaking problem goes off..
0
9879
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,...
0
10921
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10541
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
9727
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
8099
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
7250
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5939
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
6142
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3360
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.